1) static contructor should be parameterless and no modifier
2) static method can also be inherited in c#.
Notice that, the inheritance of a static method is not actually "copied the method/instance", the derived classes share same instance with the base class, if any class modifed the shared object, may causing other derived class exception.
3) static contructor can only be invoked while its static properties or variables being accessed.
Thus, following code will fail.
class Base
{
public StringBuilder SB;
}
class Derived:Base
{
static Derived()
{
//this block will not be accessed while accessing SB
SB = new StringBuilder();
}
}
void main()
{
Derived.SB.ToString();
}


Comments:
You can leave a comment on this post if you login