C# program to demonstrate the static constructor in the structure
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to demonstrate the static constructor inside the structure is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a structure StructDemo and a class Test. The StructDemo structure contains a static and non-static constructor. The static constructor is always called before the first instance of the structure gets created.
Now look to the Test class that contains the Main() method. The Main() method is the entry point for the program. Here, we printed a message "Main() method called" on the console screen. Then we created the two instances then a static construct gets called after then non-static constructor called for both instances.