匿名类型VS动态类型 [英] Anonymous Type vs Dynamic Type

查看:210
本文介绍了匿名类型VS动态类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是匿名类型(VAR)之间的真正区别C#3.0的动态类型(动态)即将在C#4.0?

What are the real differences between anonymous type(var) in c# 3.0 and dynamic type(dynamic) that is coming in c# 4.0?

推荐答案

一位不愿透露姓名的类型是你创建的一个真实的,编译器生成的类型。关于这个的好处是,编译器可以在以后重新使用这种类型的需要,因为它是一个POCO等操作。

An anonymous type is a real, compiler-generated type that is created for you. The good thing about this is that the compiler can re-use this type later for other operations that require it as it is a POCO.

我的动态类型的理解是,他们是后期绑定,这意味着CLR(或DLR)将评估对象在执行时再使用鸭打字来允许或禁止成员访问对象。

My understanding of dynamic types is that they are late-bound, meaning that the CLR (or DLR) will evaluate the object at execution time and then use duck typing to allow or disallow member access to the object.

所以我想不同的是,匿名类型是真正的波苏斯编译器可以看到,但你可以只使用和动态类型是后期绑定的动态对象。

So I guess the difference is that anonymous types are true POCOs that the compiler can see but you can only use and dynamic types are late-bound dynamic objects.

这篇关于匿名类型VS动态类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆