public static void Show() { PersonCtor person_without_param = new PersonCtor(); Util.PrintTitle(delegate() { person_without_param.OutputInfo(); }, "无参数实例构造函数"); PersonCtor person_with_param = new PersonCtor("siwing", 101, "Male", 19596); Util.PrintTitle(delegate() { person_with_param.OutputInfo(); }, "带参数实例构造函数"); Util.PrintTitle(delegate() { SubClass.DoConstructorInheritance(); }, "子类调用基类的构造函数"); //try //{ // 该语句会导致编译不通过 // // Console.WriteLine(person_with_param.static_var); // Console.WriteLine(PersonCtor.static_var); //} //catch //{ // Console.WriteLine("发生异常"); //} Util.PrintTitle(delegate() { PersonStaticConstructor.Show(); }, "静态构造函数"); Util.PrintTitle(delegate() { PersonAttr.Show(); }, "属性"); Util.PrintTitle(delegate() { IndexerArray.Show(); }, "索引器"); Util.PrintTitle(delegate() { TypeConvert.ShowConvert(); }, "类型转换"); }
public static void Show() { Console.WriteLine("第一次实例化 PersonStaticConstructor"); PersonStaticConstructor person_static = new PersonStaticConstructor(); Console.WriteLine("第二次实例化 PersonStaticConstructor"); person_static = new PersonStaticConstructor(); }