Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the .NET Colors class not static?

Tags:

c#

.net

I was browsing the colors class's source in reflector and it's just a sealed class. But all members are static. So why would anyone create a copy of the Colors class?

It lies inside:

System.Windows.Media.Colors
like image 328
Joan Venge Avatar asked Dec 08 '25 08:12

Joan Venge


1 Answers

A static class is just a sealed abstract class with private constructor no constructors (as in, no constructors at any accessibility level, not even ones generated by the compiler) [fixed per Eric's comment]. The C# keyword static is simply a shorthand for that, and also forces you to make all members static, but for API clients it's exact same thing.

Given that work on WPF (then Avalon) began before .NET 2.0 was released, it could be that this particular class was written before static class appeared. Or perhaps the author was simply unaware of that language feature.

like image 145
Pavel Minaev Avatar answered Dec 12 '25 05:12

Pavel Minaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!