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

Is string a data type in c#?

663


Explain the three services model (three-tier application). Presentation (ui), business (logic and underlying code) and data (from storage or other sources).

683


In gridview in editmode if we want to display information in one combobox based on

2049


what are nullable types in c#

739


Can we set image Source dynamically using C# in WPF application?

848


What is an assembly qualified name

785


What is method in c#?

649


Write a sample code to write the contents to text file in c#?

666


Can we overload indexer in c#?

670


Is c# a strongly-typed language?

724


What is distribute by in hive?

751


What is parsing?

695


What is CLR and its application.?

749


Which controls do not have events?

764


Why should I use interface in c#?

716