Posts

Showing posts from September, 2013

Static Class and Static Constructor

Static class is the class having static member(s) only and it is called only once when it is loaded first time. The class loads at the time of its first use. It can have static contractor. Off course, static member cannot access non-static member (instance member) variable. Static constructor is same as normal constructor which is used to initialize static variable(s), but the differences are- It cannot be overloaded nor takes any parameter as an argument. Normal constructor is used for instantiation of an object and to initialize it. It called as Instance Constructor where as Static Constructor is called as Class Constructor or Type Initializer . Static constructor is provided by C#. Twist: In general, a constructor is called at the time of instantiation but we cannot create instance of a static class, then at what time it will execute?  Answer is- only first time when it loads & being used to initialize its static variable. public static clas