Do you have another answer to this question? Click here

Static constractors in C#

Click to Rate this Question 1 Votes
are there static ctors in c#? if so what are they for?
 
 

Question Information

 
Posted Date
02 2010
Industries
Occupations
Company
Microsoft
Country
Israel
City
Hertzliya
 

Question

Are static constractors exists in c#? if so, what they used for?

 
 
 
1 Answer
 
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with keyword. A static constructor does not take access modifiers or have parameters and can't access any non-static data member of a class.

Since static constructor is a class constructor, they are guaranteed to be called as soon as we refer to that class or by creating an instance of that class.


02/11/2010
 
 
 
Add Your Answer*
 
Email