开销未使用QUOT;采用"声明? [英] overhead to unused "using" declarations?

查看:134
本文介绍了开销未使用QUOT;采用"声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了ReSharper并且它让我知道我不是实际使用中的每个我类的命名空间。

I've just installed resharper and it's letting me know the namespaces i'm not actually using in each of my classes.

这导致我的问题 - 是否有实际离开这些的任何开销,未使用的,使用报关单

which lead me to the question - is there actually any overhead in leaving these, unused, using declarations in?

是它只是一个紧code的事情,或者是有一个性能命中中调用这些命名空间时,我不需要?

is it just a matter of tight code, or is there a performance hit in invoking these namespaces when i don't need to?

推荐答案

C#球队的解答常见问题:

当您添加程序集引用或
  利用'使用'的关键字,
   CSC.EXE将忽略任何组件,
  你还没有真正用到了
  您code
...不[垃圾]你的时间剥离出来
  使用的语句或程序集使用
  从应用程序引用。
  C#编译器会为你做这样
  自动

When you add assembly references or make use of the 'using' keyword, csc.exe will ignore any assembly which you have not actually made use of in your code ... Don't [waste] your time stripping out unused 'using' statements or assembly references from your application. The C# compiler will do so for you automatically.

您可以验证这其实是通过调用 Assembly.GetReferencedAssemblies()的情况;你会看到什么,不使用实际上不会包括在列表中。

You can verify that this is actually the case by calling Assembly.GetReferencedAssemblies(); you'll see that anything that isn't used won't actually be included in the list.

在剔除未使用的主要工具是

The main utility in stripping out unused ones is


  • 这是比较容易看到你的code实际上是用什么

  • 这将让你的智能感知从事情,你实际上并没有打算使用被污染。

这篇关于开销未使用QUOT;采用"声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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