C# FAQ: Does CSharp support static initialization blocks

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

Does C# support static initialization blocks?

Static members are initialized before the creation of the class instance and prior to the first time a member is used. An entire block of code can be specified that will be run before the class is executed—either by static method invocation or by instance variable creation.

Whereas in the Java language, such static code blocks are called "static initialization blocks", in C#, they are called "static constructors". They are invoked before the class is instantiated and prior to the first invocation of a static method.

See also


Personal tools