Steps to initialize member variables

Source: Internet
Author: User

1, First Use = for static member variable assignment, from top to bottom, then assign value, there is no = number, the default value;

2, execute static constructor, assign value to static member variable;

3, First Use = for the instance member variable assignment, from top to bottom, then assign a value, there is no = number, the default value;

4, executes the instance constructor, assigns the value to the instance member variable;

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceInitialize8 {9     class ProgramTen     { One         Private stringC1 ="I am the instance variable C1 = assigned value"; A         Private stringC2 ="I am the instance variable C2 = assigned value"; -  -         Private Static stringSC1 ="I am the static variable SC1 = assigned value"; the         Private Static stringSC2 ="I am the static variable SC2 = assigned value"; -  -  -          PublicProgram () +         { - Console.WriteLine (SC1); + Console.WriteLine (SC2); A  at Console.WriteLine (C2); - Console.WriteLine (C1); -C1 ="I am an instance variable of the constructor assignment C1"; -C2 ="I am an instance variable of the constructor assignment C2"; - Console.WriteLine (C2); - Console.WriteLine (C1); in         } -  to         StaticProgram () +         { - Console.WriteLine (SC1); the Console.WriteLine (SC2); *SC1 ="I'm a static variable assigned to a static constructor C1"; $SC2 ="I'm a static variable assigned to a static constructor C2";Panax Notoginseng Console.WriteLine (SC1); - Console.WriteLine (SC2); the         } +  A         Static voidMain (string[] args) the         { +Program P =NewProgram (); - Console.read (); $         } $     } -}

Output Result:

Steps to initialize member variables

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.