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

本文详细解析了接口与类的继承的区别,并探讨了接口实现时对类成员的影响,通过实例展示了如何使用.NET Framework中的接口和类,以及如何通过反射获取类型信息。
 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/archive/2013/03/16/2934776.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值