• To initialize static fields in a class you can use static constructor.
• A static constructor is called before an instance of a class is created
• A static constructor is called before a static member is called.
• A static constructor is called before the static constructor of a derived class.
• A static constructor does not take access modifiers or have parameters.
• A static constructor cannot be called directly.
• They are called only once.
• Can't access anything but static members.
class MyClass
{
// Static constructor
static MyClass()
{
//...
}
}
No comments:
Post a Comment