未使用的using在.NET中会影响性能吗?

11
可能重复:
为什么应该删除不必要的C# using指令?
未使用的using语句如何影响性能

在c#中,未使用的using语句会影响运行时性能吗?如果是,它会如何影响?

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; 

@AvnerShahar-Kashtan 为什么你不投票关闭呢? :-) - sloth
我在注意到重复内容后标记了它,但我不认为我现在可以投票关闭。 - Avner Shahar-Kashtan
2个回答

14
不会,但它会影响IDE的性能和项目的编译过程。我可以给你举个简单的例子。如果你曾经使用过devexpress的coderush http://devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/,他们的IDE优化器和代码优化器也会建议你删除未使用的命名空间。
更新:这里有更多来自Dmitriy博客的有用信息。有几个原因可以解释为什么应该删除C#代码中未使用的using。
•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

有几种方法可以删除那些未使用的using语句,你可以在每个文件中逐个进行操作。

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

你也可以下载名为 batchFormat 的插件,它可以帮助你删除整个项目中未使用的所有 using。该插件适用于 Visual Studio 2010。

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


0
不,它们并没有。事实上,无论使用与否,它们都没有任何运行时意义。它们只是编译时常量,以允许编译器在不显式指定完整名称的情况下识别类型。
它们的主要问题是一个文件中充满了未使用的 "using" 强制你在查看代码时进行无意义的向下翻页。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接