接口是把公共实例(非静态)方法和属性组合起来,以封装特定功能的一个集合。接口是一种规范,也是一种能力
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 IPerson p = new Teacher(); 6 p.SayHello(); 7
8 Teacher t = new Teacher(); 9 t.SayHello(); 10
11 Console.ReadKey(); 12 } 13 } 14 class Teacher: IPerson 15 { 16 public void SayHello() 17 { 18 Console.WriteLine("Hello World!"); 19 } 20 } 21
22 interface IPerson 23 { 24 void SayHello(); 25 }
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 IPerson p = new Teacher(); 6 p.SayHello(); 7
8 Console.ReadKey(); 9 } 10 } 11 class Teacher: IPerson 12 { 13 void IPerson.SayHello() 14 { 15 Console.WriteLine("Hello World!"); 16 } 17 } 18
19 interface IPerson 20 { 21 void SayHello(); 22 }



1 class Program 2 { 3 static void Main(string[] args) 4 { 5 IPerson p = new TeacherSon(); 6 p.SayHello(); 7
8 Console.ReadKey(); 9 } 10 } 11 abstract class Teacher : IPerson 12 { 13 public void SayHello() 14 { 15 Console.WriteLine("Hello World!"); 16 } 17 } 18
19 class TeacherSon : Teacher 20 { 21
22 } 23
24 interface IPerson 25 { 26 void SayHello(); 27 }
