Static Classes in .Net

  • Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class.
  • To separate data and behavior that is independent of any object identity
  • Static classes can be used when there is no data or behavior in the class which depends on object identity.
  • Can be use for storing single-ton instances, global data.
  • A static constructor is used to initialize any static data. This is called only once
  • A static constructor is used to perform a specific action that needs performed once only.
  • A static constructor is called automatically before the first instance is created or any static members are referenced.
  • Static Classes are Sealed and only contains Static Members
  • Static Classes Cannot be instantiated
  • Static Classes can be use for Helper Methods.
static class MyStaticClass
{
    public static string GetName() { return "Name"; }
    public static string GetAddress() { return "Address"; }
    //...
}