简体   繁体   English

删除不必要的命名空间(使用)指令是否有性能提升?

[英]Is there a performance gain in removing unnecessary namespace (using) directives?

Does it matter how many using compiler directives are in my classes? 在我的类中使用编译器指令有多少是否重要? Is there a performance gain in removing those that aren't necessary? 删除不必要的那些是否有性能提升?

Although I enjoy writing streamlined code, on occasion, code segments get modified, and don't have the opportunity to go back and check to see if all of the included namespaces are really necessary. 虽然我喜欢编写简化的代码,但有时会修改代码段,并且没有机会返回并检查是否所有包含的命名空间都是必需的。 Or, I don't go back and remove those that are auto-inserted by visual studio. 或者,我不会回去删除visual studio自动插入的那些。

ie: 即:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

Thanks! 谢谢!

No, there's no performance advantage. 不,没有性能优势。

The compiler doesn't generate IL (executable code) for using statements. 编译器不会为using语句生成IL(可执行代码)。 IL is only generated for those classes, method calls, etc. that take advantage of the using statements you provide. IL仅为那些using您提供的using语句的类,方法调用等生成。

Consequently, the only effect unused using statements might have is to slightly increase your build time, or make the next developer after you wonder why they are there. 因此, using语句未using的唯一效果可能是略微增加构建时间,或者在您想知道它们为什么存在之后让下一个开发人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM