views:

95

answers:

2

A non static class can have static as well as default constructor at the same time.

What is the difference between these two constructors? When shall I go for only static or static with default constructor?

+2  A: 

A static constructor runs only once, no matter how many objects of that type are created. A default constructor will run for each instance created by that constructor.

Stephen Cleary
+6  A: 

Static constructor runs once per AppDomain just before you access the instance of class first time. You can use it to initialize static variables.

On the other hand default constructor runs every time you create new instance of the class. in default constructor you can initialize non-static fields of the instance.

Giorgi