加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 每种类型的标识符的正确术语是什么?

发布时间:2020-12-15 18:09:42 所属栏目:百科 来源:网络整理
导读:请使用以下代码: IFoo foo = new FooImplementation(); 标识符foo有两种类型: IFoo – 这是编译器将强制执行的类型.我只能调用属于IFoo契约的方法,否则我会遇到编译器错误. FooImplementation – 这是运行时已知的类型.我可以在运行时将foo向下转换为FooIm
请使用以下代码:
IFoo foo = new FooImplementation();

标识符foo有两种类型:

> IFoo – 这是编译器将强制执行的类型.我只能调用属于IFoo契约的方法,否则我会遇到编译器错误.
> FooImplementation – 这是运行时已知的类型.我可以在运行时将foo向下转换为FooImplementation,然后调用FooImplementation的非IFoo方法.

我的问题:这两种类型的正确术语是什么.我可以在学校发誓,我们被告知IFoo是标识符的静态类型,而FooImplementation是它的动态类型,但经过大量搜索后我似乎无法找到任何参考.

解决方法

我将分别调用IFoo和FooImplementation编译时和运行时类型. C#规范使用这种语言,例如,在谈论虚拟方法时(第1.6.6.4节):

When a virtual method is invoked,the run-time type of the instance for which that invocation takes place determines the actual method implementation to invoke. In a nonvirtual method invocation,the compile-time type of the instance is the determining factor.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读