This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17265|Reply: 0

[Source] Execution of C# static constructors

[Copy link]
Posted on 12/12/2016 2:17:32 PM | | | |



There are a few things you should pay attention to when using static constructors:

1. The static constructor has neither access modifiers nor parameters. Because it is. .NET call, so modifiers like public and private don't make sense.

2. When the first class instance is created or any static member is referenced, . .NET will automatically call the static constructor to initialize the class, which means that we cannot call the static constructor directly, so we have no control over when the static constructor is executed.

3. A class can only have one static constructor.

4. Parameterless constructors can coexist with static constructors. Although the list of parameters is the same, one belongs to the class and one belongs to the instance, so there is no conflict.

5. Run only once at most.

6. Static constructors cannot be inherited.

7. If no static constructor is written, and the class contains static members with initial value settings, then the compiler will automatically generate the default static constructor.






Previous:How to set up software boot automatically.
Next:python module from Crypto.Cipher import AES
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com