//static void Main(string[] args) //{ // GenericStack<int> objStack = new GenericStack<int>(10); // objStack.Push(2); // objStack.Push(3); // objStack.Push(5); // Console.WriteLine(objStack.Pop().ToString()); // Console.WriteLine(objStack.Pop().ToString()); // Console.WriteLine(objStack.Pop().ToString()); // Console.ReadLine(); //} #endregion #region 带约束的泛型类测试 static void Main(string[] args) { //1实例化泛型类型对象 MyGenericClass2 <int, Course, Teacher> obj1 = new MyGenericClass2 <int, Course, Teacher>(); //2给对象的属性赋值 obj1.publisher = new Teacher() { Name = "HuHu", Count = 20 }; obj1.productList = new List <Course>() { new Course() { CourseName = "c#", Period = 20 }, new Course() { CourseName = "c1", Period = 1 }, new Course() { CourseName = "c2", Period = 2 }, new Course() { CourseName = "c3", Period = 3 }, }; //3调用对象方法 Course objCourse = obj1.Buy(0); //4数据处理 string info = string.Format("我已购买课程{0},学时{1},授课老师{2}", objCourse.CourseName, objCourse.Period, obj1.publisher.Name ); Console.WriteLine(info); Console.ReadLine(); }
public static void Test() { MyGenericClass2 <int> genericClass21 = new MyGenericClass2 <int>(); //MyGenericClass2<MyClass1> genericClass22 = new MyGenericClass2<MyClass1>(); //MyGenericClass2<MyClass2> genericClass23 = new MyGenericClass2<MyClass2>(); //MyGenericClass2<MyClass3> genericClass24 = new MyGenericClass2<MyClass3>(); //MyGenericClass2<MyClass4> genericClass25 = new MyGenericClass2<MyClass4>(); //MyGenericClass2<MyClass5> genericClass26 = new MyGenericClass2<MyClass5>(); //MyGenericClass2<MyClass6> genericClass27 = new MyGenericClass2<MyClass6>(); //MyGenericClass3<int> genericClass31 = new MyGenericClass3<int>(); //MyGenericClass3<MyClass1> genericClass32 = new MyGenericClass3<MyClass1>(); //MyGenericClass3<MyClass2> genericClass33 = new MyGenericClass3<MyClass2>(); //MyGenericClass3<MyClass3> genericClass34 = new MyGenericClass3<MyClass3>(); //MyGenericClass3<MyClass4> genericClass35 = new MyGenericClass3<MyClass4>(); //MyGenericClass3<MyClass5> genericClass36 = new MyGenericClass3<MyClass5>(); //MyGenericClass3<MyClass6> genericClass37 = new MyGenericClass3<MyClass6>(); //MyGenericClass4<int> genericClass41 = new MyGenericClass4<int>(); MyGenericClass4 <MyClass1> genericClass42 = new MyGenericClass4 <MyClass1>(); MyGenericClass4 <MyClass2> genericClass43 = new MyGenericClass4 <MyClass2>(); MyGenericClass4 <MyClass3> genericClass44 = new MyGenericClass4 <MyClass3>(); MyGenericClass4 <MyClass4> genericClass45 = new MyGenericClass4 <MyClass4>(); MyGenericClass4 <MyClass5> genericClass46 = new MyGenericClass4 <MyClass5>(); MyGenericClass4 <MyClass6> genericClass47 = new MyGenericClass4 <MyClass6>(); //MyGenericClass5<int> genericClass51 = new MyGenericClass5<int>(); //MyGenericClass5<MyClass1> genericClass52 = new MyGenericClass5<MyClass1>(); //MyGenericClass5<MyClass2> genericClass53 = new MyGenericClass5<MyClass2>(); //MyGenericClass5<MyClass3> genericClass54 = new MyGenericClass5<MyClass3>(); //MyGenericClass5<MyClass4> genericClass55 = new MyGenericClass5<MyClass4>(); MyGenericClass5 <MyClass5> genericClass56 = new MyGenericClass5 <MyClass5>(); MyGenericClass5 <MyClass6> genericClass57 = new MyGenericClass5 <MyClass6>(); //MyGenericClass6<int> genericClass61 = new MyGenericClass6<int>(); MyGenericClass6 <MyClass1> genericClass62 = new MyGenericClass6 <MyClass1>(); //MyGenericClass6<MyClass2> genericClass63 = new MyGenericClass6<MyClass2>(); MyGenericClass6 <MyClass3> genericClass64 = new MyGenericClass6 <MyClass3>(); MyGenericClass6 <MyClass4> genericClass65 = new MyGenericClass6 <MyClass4>(); //MyGenericClass6<MyClass5> genericClass66 = new MyGenericClass6<MyClass5>(); MyGenericClass6 <MyClass6> genericClass67 = new MyGenericClass6 <MyClass6>(); MyGenericClass7 <int> genericClass71 = new MyGenericClass7 <int>(); //MyGenericClass7<MyClass1> genericClass72 = new MyGenericClass7<MyClass1>(); //MyGenericClass7<MyClass2> genericClass73 = new MyGenericClass7<MyClass2>(); //MyGenericClass7<MyClass3> genericClass74 = new MyGenericClass7<MyClass3>(); //MyGenericClass7<MyClass4> genericClass75 = new MyGenericClass7<MyClass4>(); MyGenericClass7 <MyClass5> genericClass76 = new MyGenericClass7 <MyClass5>(); MyGenericClass7 <MyClass6> genericClass77 = new MyGenericClass7 <MyClass6>(); //MyGenericClass8<int> genericClass81 = new MyGenericClass8<int>(); //MyGenericClass8<MyClass1> genericClass82 = new MyGenericClass8<MyClass1>(); //MyGenericClass8<MyClass2> genericClass83 = new MyGenericClass8<MyClass2>(); //MyGenericClass8<MyClass3> genericClass84 = new MyGenericClass8<MyClass3>(); //MyGenericClass8<MyClass4> genericClass85 = new MyGenericClass8<MyClass4>(); MyGenericClass8 <MyClass5> genericClass86 = new MyGenericClass8 <MyClass5>(); MyGenericClass8 <MyClass6> genericClass87 = new MyGenericClass8 <MyClass6>(); //MyGenericClass9<int> genericClass91 = new MyGenericClass9<int>(); //MyGenericClass9<MyClass1> genericClass92 = new MyGenericClass9<MyClass1>(); //MyGenericClass9<MyClass2> genericClass93 = new MyGenericClass9<MyClass2>(); //MyGenericClass9<MyClass3> genericClass94 = new MyGenericClass9<MyClass3>(); //MyGenericClass9<MyClass4> genericClass95 = new MyGenericClass9<MyClass4>(); //MyGenericClass9<MyClass5> genericClass96 = new MyGenericClass9<MyClass5>(); MyGenericClass9 <MyClass6> genericClass97 = new MyGenericClass9 <MyClass6>(); MyGenericClass10 <int> genericClass101 = new MyGenericClass10 <int>(); MyGenericClass10 <MyClass1> genericClass102 = new MyGenericClass10 <MyClass1>(); //MyGenericClass10<MyClass2> genericClass103 = new MyGenericClass10<MyClass2>(); MyGenericClass10 <MyClass3> genericClass104 = new MyGenericClass10 <MyClass3>(); MyGenericClass10 <MyClass4> genericClass105 = new MyGenericClass10 <MyClass4>(); MyGenericClass10 <MyClass5> genericClass106 = new MyGenericClass10 <MyClass5>(); MyGenericClass10 <MyClass6> genericClass107 = new MyGenericClass10 <MyClass6>(); //MyGenericClass11<int> genericClass111 = new MyGenericClass11<int>(); MyGenericClass11 <MyClass1> genericClass112 = new MyGenericClass11 <MyClass1>(); //MyGenericClass11<MyClass2> genericClass113 = new MyGenericClass11<MyClass2>(); MyGenericClass11 <MyClass3> genericClass114 = new MyGenericClass11 <MyClass3>(); MyGenericClass11 <MyClass4> genericClass115 = new MyGenericClass11 <MyClass4>(); MyGenericClass11 <MyClass5> genericClass116 = new MyGenericClass11 <MyClass5>(); MyGenericClass11 <MyClass6> genericClass117 = new MyGenericClass11 <MyClass6>(); //MyGenericClass12<int> genericClass121 = new MyGenericClass12<int>(); MyGenericClass12 <MyClass1> genericClass122 = new MyGenericClass12 <MyClass1>(); //MyGenericClass12<MyClass2> genericClass123 = new MyGenericClass12<MyClass2>(); MyGenericClass12 <MyClass3> genericClass124 = new MyGenericClass12 <MyClass3>(); MyGenericClass12 <MyClass4> genericClass125 = new MyGenericClass12 <MyClass4>(); //MyGenericClass12<MyClass5> genericClass126 = new MyGenericClass12<MyClass5>(); MyGenericClass12 <MyClass6> genericClass127 = new MyGenericClass12 <MyClass6>(); MyGenericClass13 <int> genericClass131 = new MyGenericClass13 <int>(); //MyGenericClass13<MyClass1> genericClass132 = new MyGenericClass13<MyClass1>(); //MyGenericClass13<MyClass2> genericClass133 = new MyGenericClass13<MyClass2>(); //MyGenericClass13<MyClass3> genericClass134 = new MyGenericClass13<MyClass3>(); //MyGenericClass13<MyClass4> genericClass135 = new MyGenericClass13<MyClass4>(); MyGenericClass13 <MyClass5> genericClass136 = new MyGenericClass13 <MyClass5>(); MyGenericClass13 <MyClass6> genericClass137 = new MyGenericClass13 <MyClass6>(); //MyGenericClass14<int> genericClass141 = new MyGenericClass14<int>(); //MyGenericClass14<MyClass1> genericClass142 = new MyGenericClass14<MyClass1>(); //MyGenericClass14<MyClass2> genericClass143 = new MyGenericClass14<MyClass2>(); //MyGenericClass14<MyClass3> genericClass144 = new MyGenericClass14<MyClass3>(); //MyGenericClass14<MyClass4> genericClass145 = new MyGenericClass14<MyClass4>(); MyGenericClass14 <MyClass5> genericClass146 = new MyGenericClass14 <MyClass5>(); MyGenericClass14 <MyClass6> genericClass147 = new MyGenericClass14 <MyClass6>(); }