未使用using语句 [英] Unused using statements

查看:217
本文介绍了未使用using语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能已经知道这个问题的答案,但我认为这是值得一问反正。如果我有使用的负载不的使用我的代码文件中的语句的;




  1. 这是否有任何形式的不利影响性能?

  2. 如何在编译/运行时间与他们做编译器处理?



感谢


解决方案

这是否有任何形式的不利影响性能?




没有。




编译器如何处理他们在编译/运行时间呢?




在编译的时候他们做你所期望的东西,也就是充当进口的命名空间。它们不会出现在编译的二进制:一个类型的任何参考使用完全合格的域名



该编译器检查命名空间在使用,即使不是需要它语句;如果你删除一个命名空间,那么所有引用它的使用语句将失败。



对我来说,多余的使用语句就像多余的注释。它们使编译器没有什么区别,但有太多了,和你的风险迷惑你的开发人员。


I may already know the answer to this question, but I thought it was worth asking anyway. If I have a load of using statements within my code file that aren't being used;

  1. Does that have any sort of detrimental performance impact?
  2. How does the compiler deal with them at compile/run time?

Thanks

解决方案

does that have any sort of detrimental performance impact?

No.

How does the compiler deal with them at compile/run time?

At compile time they do what you'd expect, i.e. act as namespace imports. They don't appear in the compiled binary: any reference to a type uses the fully-qualified name.

The compiler does check the namespace in a using statement even if it's not needed; if you remove a namespace, then all the using statements that refer to it will fail.

To me, redundant using statements are like redundant comments. They make no difference to the compiler, but include too many of them, and you risk confusing your developers.

这篇关于未使用using语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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