In the blog, you can see other people's explanation of the static constructor. I am not quite clear about it.
Using system; using system. collections. generic; using system. text; namespace consoleapplication1 {public class test {static test () {console. writeline ("I Am a static constructor");} public test () {console. writeline ("I am the initialization method");} public static void write () {console. writeline ("I want to write something on the screen"); console. writeline ("Hello world !!! ") ;}} Public class program {# region calls the static method to execute the static constructor // static void main (string [] ARGs) // {// test. write (); // console. readkey (); //} # endregion # When region creates the first test class, it executes the static constructor static void main (string [] ARGs) {test TST = new test (); console. readkey () ;}# endregion }}
A static constructor is used to initialize any static data or perform a specific operation that only needs to be performed once. The static constructor is automatically called before the first instance is created or any static member is referenced.