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
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
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.
For me, Colors.AliceBlue and Colors.AntiqueWhite (the first and the second static property of Colors class :)) should be difference instances of Color objects instead of different types.
public static Color AliceBlue {get;}
Please note that a static class is a sealed class that contains only static members and cannot be instantiated using the new keyword as it can only have a private default constructor (at least in C#).
Imagine you are creating an API that takes Color as an argument, what will it look like if the Color is a static class?
One can argue that different colors should be different types (arguably static as well) instead of different instances of the Color class. Even with this case, Color should not be a static class because you want to have a base Color class for individual Color classes and making the base Color class static automatically makes it sealed.
One may still want to argue that Color should be a namespace and individual colors should be static classes. I will simply ask them to imagine what the API will look like again :)