What is static constructor?

C# Programming Language >   OOPS Concept >   Introduction to OOP Concept  

Short Question

732


Answer:

Static constructor is used to initialize static data members as soon as the class is referenced first time.


class SimpleClass
{
    // Static variable that must be initialized at run time.
    static readonly long baseline;

    // Static constructor is called at most one time, before any
    // instance constructor is invoked or member is accessed.
    static SimpleClass()
    {
        baseline = DateTime.Now.Ticks;
    }
}


A static constructor is used to initialize any


This Particular section is dedicated to Question & Answer only. If you want learn more about C# Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.