C # static Constructor

Source: Internet
Author: User

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.
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.