请不要在.NET中未使用的usings影响性能? [英] Do unused usings in .net affect performance?

查看:315
本文介绍了请不要在.NET中未使用的usings影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
  <一href="http://stackoverflow.com/questions/136278/why-should-you-remove-unnecessary-c-sharp-using-directives">Why你应该删除不必要C#using指令?
  <一href="http://stackoverflow.com/questions/1162766/how-is-performance-affected-by-an-unused-using-statement">How在性能受到了using语句未使用

不要在C#中使用的usings影响运行时性能?如果是的话,怎么办呢?

 使用系统;
使用System.Collections.Generic;
使用System.ComponentModel; ----- //未使用
使用System.Data这; --------------- //未使用
使用System.Drawing中; ----------- //未使用
使用System.Text; ------------- //未使用
使用System.Windows.Forms的;
使用的System.Threading; ------ //未使用
使用System.Linq的; ---------- //未使用
使用System.IO; ----------- //未使用
使用System.Diagnostics程序;  -  //未使用
使用System.Data.OleDb;
使用OBID;
 

解决方案

没有,但它影响IDE的性能和编制项目的进程。 我可以给你一个简短的例子。如果你曾经使用$ C $美眉<一href="http://devex$p$pss.com/Products/Visual_Studio_Add-in/Coding_Assistance/">http://devex$p$pss.com/Products/Visual_Studio_Add-in/Coding_Assistance/这是devex preSS,他们的IDE优化和code优化也将建议您删​​除未使用的命名空间。

更新:下面是更多的使用距离德米特里的博客信息 有几个原因,你应该删除未使用的usings在你的C#code。

 •这是无用的code,这只是在你的源$ C ​​$ C造成混乱,同时也混淆了开发人员,因为你不知道哪个名字空间实际使用。
•随着时间的推移作为你的code变化,它可以积累很多这在创建更加混乱code未使用using语句中。
•它可以让你的编译更快,因为编译器不具备查找所有这些额外的未使用的命名空间。
•这将有助于避免与你要添加到您的解决方案,如果这两个具有相同名称的新项目名称冲突。
•它会降低你的Visual Studio编辑器自动完成的项目数量
 

有几个方法可以删除那些未使用的usings,你可以单独做到这一点对每个文件

<一个href="http://msdn.microsoft.com/en-us/library/bb514115.aspx">http://msdn.microsoft.com/en-us/library/bb514115.aspx

您也可以下载插件叫做batchFormat为Visual Studio 2010中,可以帮助你删除所有未使用usings为整个项目。

<一个href="http://www.addictivetips.com/windows-tips/batch-format-remove-unused-usings-and-format-visual-studio-document/">http://www.addictivetips.com/windows-tips/batch-format-remove-unused-usings-and-format-visual-studio-document/

Possible Duplicate:
Why should you remove unnecessary C# using directives?
How is performance affected by an unused using statement

Do unused usings in c# affect runtime performance? If yes, How do so?

using System;
using System.Collections.Generic;
using System.ComponentModel; -----//Unused
using System.Data;---------------//Unused
using System.Drawing;-----------//Unused
using System.Text;-------------//Unused
using System.Windows.Forms;
using System.Threading;------//Unused
using System.Linq;----------//Unused
using System.IO;-----------//Unused
using System.Diagnostics;-//Unused
using System.Data.OleDb;
using OBID; 

解决方案

NO, but It effects the IDE performance and the compilation process of your project. I can give you a short example. If you have ever used coderush http://devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/ which is from devexpress, their IDE optimizer and code optimizer will also suggest you to remove unused namespaces.

Update: Here is more use information from Dmitriy's Blog There are few reasons why you should remove unused usings in you C# code.

•It is useless code, that just creates clutter in your source code and it also confusing for the developer because you don’t know which namespaces are actually used.
•Over time as your code changes it can accumulate a lot of unused using statements which create even more clutter in you code.
•It can make your compiling faster, since compiler does not have to look up all those extra unused namespaces.
•It will help avoid name conflict with new items that you going to add to your solution if both of those have same names.
•It will reduce number of items in your Visual Studio editor auto completion

There are couple ways to remove those unused usings, you can do it individually on each file

http://msdn.microsoft.com/en-us/library/bb514115.aspx

You also can download plugin called batchFormat for Visual Studio 2010 that can help you to remove all unused usings for the whole project.

http://www.addictivetips.com/windows-tips/batch-format-remove-unused-usings-and-format-visual-studio-document/

这篇关于请不要在.NET中未使用的usings影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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