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