// C# allows value types to have constructors that take parameters. public SomeValType(Int32 x) { // Looks strange but compiles fine and initializes all fields to 0/null. this = new SomeValType(); m_x = x; // Overwrite m_x's 0 with x // Notice that m_y was initialized to 0. }
static void Main() { // Doesn't hit static constructor SomeValType v = new SomeValType(); v.bar = 1; // Hits static constructor SomeValType.foo = 3; }
public static void Main() { SomeValType[] a = new SomeValType[10]; a[0].m_x = 123; Console.WriteLine(a[0].m_x); // Displays 123 new FieldInitializationInCtor("Test"); TypeConstructorPerformance.Go(); ConversionOperator.Go(); ExtensionMethods.Go(); }
public static void Main() { SomeValType[] a = new SomeValType[10]; a[0].m_x = 123; Console.WriteLine(a[0].m_x); // Displays 123 //new FieldInitializationInCtor("Test"); //TypeConstructorPerformance.Go(); //ConversionOperator.Go(); //ExtensionMethods.Go(); PartialMethodsDemo.Go(); //HenryTien henry = new HenryTien(520); //henry.Hello(); }