What is the use of the static constructor? When static
constructor gets compiled?

Answer Posted / jitendra

Static constructor is used to initzialise the static data
members when the class has been instantiated first time.
Static data members can certainly be initialized at the
time of their declaration but there are times when value of
one static member may depend upon the value of another
static member. In such cases we definitely need some
mechanism to handle conditional initialization of static
members. To handle such situation, C# provides static
constructor.

Is This Answer Correct ?    20 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I create a multi language, multi file assembly?

617


What are annotations in c#?

519


What is datarelation c#?

460


What is dataset c#?

485


What is the difference between console and windows application?

445






What will a loop recorder show?

542


What are strings in c#?

483


What is serialization in .net?

558


What is a static class in c#?

502


What is int16?

502


What are custom exceptions?

525


Can an int be negative c#?

579


What is difference between sleep () and wait ()?

485


Why delegate is used in c#?

467


What is the real use of interface in c#?

459