动态关键字与对象数据类型 [英] dynamic keyword vs object data type
问题描述
这两个变量定义有什么不同?
What is different between this two variable definitions?
object oVar;
dynamic dVar;
性能?内存分配?好处?
Performance? Memory allocation? Benefits?
推荐答案
编译器将一个变量类型化为 object
并且所有实例成员都将被编译器验证为有效.另一个变量的类型为 dynamic
,所有实例成员都将被编译器忽略并在执行时由 DLR 调用.
One variable is typed as object
by the compiler and all instance members will be verified as valid by the compiler. The other variable is typed as dynamic
and all instance members will be ignored by the compiler and called by the DLR at execution time.
它与性能或内存分配无关.dynamic
类型是编译器在某种程度上忽略的静态类型.它使您能够在静态类型语言中使用鸭子输入,这提供了很大的灵活性(尤其是在处理用更动态的语言编写的组件时).
It has nothing to do with either performance or memory allocation. The dynamic
type is a static type that the compiler somewhat ignores. It gives you the ability to use duck typing in a statically typed language which provides a lot of flexibility (especially when dealing with components written in languages that are more dynamic).
我绝对建议您阅读以下主题:
I would definitely recommend that you read up on the following topics:
这篇关于动态关键字与对象数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!