对于接口的理解

AE官方原文:

Casting in C#

In C#, the best method for casting between interfaces is to use the as operator. Using the as operator is a better coding strategy than a straight cast, because it yields a null on a conversion failure rather than raising an exception.

The first line in the following code example is a straight cast. This is an acceptable practice if you are certain the object in question implements both interfaces. If the object does not implement the interface you are attempting to get a handle to, .NET throws an exception. A safer model to use is the as operator, which returns a null if the object cannot return a reference to the desired interface.

 

个人理解:

接口就是包含了方法、属性定义的一个容器,本身不包含实现方法、给属性赋值的代码。

类继承了一个接口,该类就必须实现这个接口内定义声明的方法和函数。

所谓的接口跳转,是针对同一个类中继承的接口,对于该类实例化的对象,可以跳转同一个类中的不同的接口,使用不同接口内定义的方法和属性。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值