Tuesday, January 31, 2006

Static constructors in C#

Some important point regarding static constructor in C# are :

1) The static constructor for a class executes before any instance of the class is created.
2) The static constructor for a class executes before any of the static members for the class are referenced.
3) The static constructor for a class executes after the static field initializers (if any) for the class.
4) The static constructor for a class executes at most one time during a single program instantiation
5) A static constructor does not take access modifiers or have parameters.
6) A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
7) A static constructor cannot be called directly.
8) The user has no control on when the static constructor is executed in the program.
9) A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.

Refrences:
1. c-sharpcorner
2. C# Language Specification
3. C# Programmer's Reference

1 comment:

Crazy Dan said...

Just thought I would stop by and say "Hello Brij." It's been a hectic
but very worthwhile last few days for me. In searching for more access control software related info on the Internet, I came across your site. I appreciate your content and I really appreciate your this post! It's been a great help in collecting more info on access control software. Thanks again and have a great day!