Monday, December 19, 2005

C# Static Classes

Static classes are meant to replace the design pattern of creating a sealed class with a private constructor that contains only static methods. A static class is denoted by placing the static modifier on the class declaration. For example: public sealed class Environment
{
// Keep class from being created
private Environment() { }
}
can now be written as: public static sealed class Environment
{
}
The benefit of using a static class instead of the design pattern above is that the compiler can now report an error if any instance methods are accidentally declared.

(from link)

No comments: