继承成员的差异:接口与类

 1  interface IBase
 2     {
 3         string Name
 4         {
 5             get;
 6             set;
 7         }
 8 
 9     }
10     interface IPenson:IBase
11     {
12         int Age
13         {
14             get;
15             set;
16         }
17     }
18     class Base
19     {
20         public string Name
21         {
22             get;
23             set;
24         }
25 
26     }
27     class Penson:Base
28     {
29         public int Age
30         {
31             get;
32             set;
33         }
34     }
35 
36     public  static class InheritTest
37     {
38         public static void Test()
39         {
40             Show(typeof(IPenson));
41             Show(typeof(Penson));
42 
43         }
44         static void Show(Type type)
45         {
46             var ps=type.GetProperties();
47             Console.WriteLine(string.Format("{0}'s PropertyInfo List:",type.Name));
48             foreach (var item in ps)
49                 Console.WriteLine(item.Name);
50             Console.WriteLine();
51         }
52   
53     }

差异:类的继承是实际的继承,而接口的继承只是确定继承的关系.

影响:当接口被实现时,类要实现的成员不单单是当前继承的接口,而是分别要实现该接口,以及该接口继承的所有接口的成员.

原文地址:https://www.cnblogs.com/AspDotNetMVC/p/2934776.html