Learn all about the new C# 2.0 Framework feature: Static Classes.
Tested with Microsoft Visual C# 2005 Beta 1, .Net 2.0.40607.42
Well, while not as exciting as many of the other new features of C# 2.0, static classes give us a faster way
of implementing classes who's only purpose is to deliver static members. While you can always just create a
class with a private constructor, so that it doesn't get instantiated, and then add all static members,
static classes enforce those requirements automatically. Static classes are sealed (they're can't be derived from),
they can't be instantiated (made an instance object from) and they can't contain a constructor.
namespace WhatsNew20StaticClasses
{
class Program
{
static void Main(string[] args)
{
MyStaticClass.PrintMessage("Hello World!");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
public static class MyStaticClass
{
public static void PrintMessage(String Message)
{
Console.WriteLine(Message);
}
}
}