Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Rules of Static Constructor
WhatsApp
Amit Tiwari
11y
4.4
k
0
0
25
Blog
Rules of Static Constructor
The static constructor for a class executes before any instance of the class is created.
The static constructor for a class executes before any of the static members for the class are referenced.
The static constructor for a class executes after the static field initializers (if any) for the class.
The static constructor for a class executes at most one time during a single program instantiation
A static constructor does not take access modifiers or have parameters.
A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
A static constructor cannot be called directly.
The user has no control on when the static constructor is executed in the program.
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.
Syntax:
class
ConstructorClass
{
// Static constructor
static
ConstructorClass ()
{
}
}
Rules of Static Constructor
Up Next
Static Constructor Vs Instance Constructor in C#
Ebook Download
View all
Mastering SOLID Principles in C#
Read by 2.7k people
Download Now!
Learn
View all
Membership not found