动态关键字VS对象数据类型 [英] dynamic keyword vs object data type
问题描述
这是什么两个可变定义之间的不同。
What is different between this two variable definitions?
object oVar;
dynamic dVar;
性能?内存分配?好处?
Performance? Memory allocation ? Benefits?
推荐答案
一个变量是由编译器类型为对象
和所有实例成员将被编译器验证为有效。 其他变量的类型为动,所有的实例成员将由编译器在执行时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.
它无关的性能或内存分配。在动态
类型是静态类型,编译器有所忽略。它为您提供了一个静态类型语言与组件打交道时提供了很大的灵活性(特别是使用鸭打字的能力。写在更动态语言)
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:
- dynamic (C# Reference)
- Using Type dynamic (C# Programming Guide)
- Dynamic Language Runtime Overview
这篇关于动态关键字VS对象数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!