这是刚刚接触继承时写的一段代码,其实当时根本没有完全理解继承,后来读了《你必须知道的.NET》,对继承有了更深入的了解,学知识还是要深究深挖,真正理解透了才能更好的应用。
View Code
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace jicheng 7 { 8 class club 9 { 10 public void method_HostTeam() 11 { 12 Console.Write("Host Team: "); 13 } 14 public void method_GuestTeam() 15 { 16 Console.Write("Guest Team: "); 17 } 18 public void method_Venues() 19 { 20 Console.Write("the venues of the match: "); 21 } 22 23 private string name_Host; 24 private string name_Guest; 25 private string name_Venues; 26 27 public string name_HostTeam 28 { 29 get 30 { 31 return this.name_Host; 32 } 33 set 34 { 35 this.name_Host = value; 36 } 37 } 38 public string name_GuestTeam 39 { 40 get 41 { 42 return this.name_Guest; 43 } 44 set 45 { 46 this.name_Guest = value; 47 } 48 } 49 50 public string name_venues 51 { 52 get 53 { 54 return this.name_Venues; 55 } 56 set 57 { 58 this.name_Venues = value; 59 } 60 } 61 62 public void getname_HostTeam() 63 { 64 Console.WriteLine(name_Host); 65 } 66 public void getname_GuestTeam() 67 { 68 Console.WriteLine(name_Guest); 69 } 70 public void getname_venues() 71 { 72 Console.WriteLine(name_Venues); 73 } 74 } 75 76 class First : club 77 { 78 public void method_HostTeam1() 79 { 80 base.method_HostTeam(); 81 } 82 public void method_GuestTeam1() 83 { 84 base.method_GuestTeam(); 85 } 86 public void method_Venues1() 87 { 88 base.method_Venues(); 89 } 90 91 public string name_HostTeam1 92 { 93 get 94 { 95 return base.name_HostTeam; 96 } 97 set 98 { 99 base.name_HostTeam = value; 100 } 101 } 102 public string name_GuestTeam1 103 { 104 get 105 { 106 return base.name_GuestTeam; 107 } 108 set 109 { 110 base.name_GuestTeam = value; 111 } 112 } 113 public string name_venues1 114 { 115 get 116 { 117 return base.name_venues; 118 } 119 set 120 { 121 base.name_venues = value; 122 } 123 } 124 } 125 126 class second : club 127 { 128 public void method_HostTeam2() 129 { 130 base.method_HostTeam(); 131 } 132 public void method_GuestTeam2() 133 { 134 base.method_GuestTeam(); 135 } 136 public void method_Venues2() 137 { 138 base.method_Venues(); 139 } 140 141 public string name_HostTeam2 142 { 143 get 144 { 145 return base.name_HostTeam; 146 } 147 set 148 { 149 base.name_HostTeam = value; 150 } 151 } 152 public string name_GuestTeam2 153 { 154 get 155 { 156 return base.name_GuestTeam; 157 } 158 set 159 { 160 base.name_GuestTeam = value; 161 } 162 } 163 public string name_venues2 164 { 165 get 166 { 167 return base.name_venues; 168 } 169 set 170 { 171 base.name_venues = value; 172 } 173 } 174 } 175 176 class Program 177 { 178 static void Main(string[] args) 179 { 180 Console.WriteLine("英格兰超级联赛第34轮\n"); 181 First club_1stHost = new First (); 182 club_1stHost.method_HostTeam1(); 183 club_1stHost.name_HostTeam1 = "布莱克本"; 184 club_1stHost.getname_HostTeam(); 185 First club_1stGuest = new First(); 186 club_1stGuest.method_GuestTeam1(); 187 club_1stGuest.name_GuestTeam1 = "曼城"; 188 club_1stGuest.getname_GuestTeam(); 189 First venues1 = new First(); 190 venues1.method_Venues(); 191 venues1.name_venues1 = "古迪逊公园球场"; 192 venues1.getname_venues(); 193 Console.WriteLine("\n"); 194 195 second club_2ndHost = new second(); 196 club_2ndHost.method_HostTeam2(); 197 club_2ndHost.name_HostTeam2 = "博尔顿"; 198 club_2ndHost.getname_HostTeam(); 199 second club_2ndGuest = new second(); 200 club_2ndGuest.method_GuestTeam2(); 201 club_2ndGuest.name_GuestTeam2 = "阿森纳"; 202 club_2ndGuest.getname_GuestTeam(); 203 second venues2 = new second(); 204 venues2.method_Venues2(); 205 venues2.name_venues2 = "锐步球场"; 206 venues2.getname_venues(); 207 } 208 } 209 }
|
请发表评论