动态VS对象类型 [英] dynamic vs object type

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

问题描述

我已经使用了动态对象类型可以互换。有这两种类型之间有什么区别?有没有使用一个比其他任何性能影响?其中哪一个更灵活?

I have used the dynamic and the object type interchangeably. Is there any difference between these two types? Is there any performance implications of using one over the other? Which one of these is more flexible?

推荐答案

他们的非常的不同。

如果您使用动态您加入到动态类型,从而选择退出的编译时检查的大部分。是的,它比使用静态类型的在这里您可以的使用静态类型较少的高性能。

If you use dynamic you're opting into dynamic typing, and thus opting out of compile-time checking for the most part. And yes, it's less performant than using static typing where you can use static typing.

但是,你不能做很多与对象键入反正 - 它几乎没有任何成员。你在哪里发现自己使用呢?当你想要写通用code可与多种类型的工作,你应该通常认为仿制药,而不是对象

However, you can't do much with the object type anyway - it has hardly any members. Where do you find yourself using it? When you want to write general purpose code which can work with a variety of types, you should usually consider generics rather than object.

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

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