在C#中,是更高性能的使用完全合格的名称相较于'用'的指令? [英] In C#, is it more performant to use fully qualified names vs the 'using' directive?

查看:125
本文介绍了在C#中,是更高性能的使用完全合格的名称相较于'用'的指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,当你添加一个 使用指令的命名空间,它使您可以访问所有类型在特定的命名空间。但是,如果命名空间有很多类型,我只需要一个特殊的一个,我经常只使用完全合格的域名以为我不希望使用任何不必要的课程,我知道我不会使用(特别是如果有很多人在命名空间)的因为性能原因。我在想,必须有一定的影响性能(无论多分钟),以使其可相对于没有,但多少? (如果确实是一个)。如果是的话,会是那么坏的做法,这样做所有的地方,因为那岂不是再开始积累的东西noticable(性能明智)?

In C#, when you add a using directive for a namespace, it gives you access to all the types in that specific namespace. However, if the namespace has a lot of types and I only need one particular one, I often just use the fully qualified name thinking that I don't want to make available any unnecessary classes I know I am not going to use (especially if there are a lot of them in that namespace) for performance reasons. I was thinking that there has to be some impact to performance (no matter how minute) to make them available as opposed to not, but how much? (if there actually is one). And if so, would it then be bad practice to do this all over the place, because wouldn't it then start to accumulate to something noticable (performance wise)?

我没有看到的<一个href="http://stackoverflow.com/questions/971612/is-fully-qualified-naming-vs-the-using-directive-simply-a-matter-of-opinion">other SO帖子关于使用使用指令VS完全合格的名字,但它不是参考的性能。

I did see the other SO post about using the using directive vs fully qualified names, but it wasn't in reference to performance.

推荐答案

使用指令只是语法糖编译期间消失。不管是不是该命名空间通过被列入使用或完全限定的类型名称提的是,在生成的字节code完全无关。因此,有在运行时没有性能优势通过使用一种或另一种。

The using directive is only syntactic sugar that disappears during compilation. Whether or not the namespace was included via using or mentioned in a fully-qualified type name is totally irrelevant in the resulting bytecode. Hence, there is no performance benefit at runtime by using one or the other.

这篇关于在C#中,是更高性能的使用完全合格的名称相较于'用'的指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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