Sunday, May 08, 2005

Instance Constructor vs. The Class Constructor

Instance Constructor vs. The Class Constructor

A good explanation of difference between the instance constructors and the class constructors.

Class constructors are used for static field initialization. Only one class constructor per type is permitted, and it cannot use the vararg (variable argument) calling convention. Normally, class constructors are never called from the IL code. If a type has a class constructor, this constructor is executed automatically after the type is loaded. However, a class constructor, like any other static method, can be called explicitly. As a result of such a call, the global fields of the type are reset to their initial values. Calling class constructor explicitly does not lead to type reloading.

No comments: