每当您创建新页面或项目时,Visual Studio都会为您自动创建语句。其中一些您将永远不会使用。

Visual Studio具有“删除未使用的使用”的有用功能。

我想知道,如果从未访问过的使用语句,是否会对程序性能产生负面影响,请在文件的顶部提到。

有帮助吗?

解决方案

未使用的使用对应用程序的运行时性能没有影响。

它可以影响IDE的性能和整体汇编阶段。之所以创建一个额外的名称空间,在其中必须发生名称分辨率。但是,这些往往很小,在大多数情况下对您的IDE经验产生明显影响。

由于相同的原因,它还可以影响调试器中评估表达式的性能。

其他提示

不,这只是一种编译时间/编码样式的内容。 .NET二进制文件在引擎盖下使用完全合格的名称。

以下链接 很好的阅读为什么要删除未使用的参考 说明从应用程序中删除未使用的引用是如何有用的。

以下是链接的一些摘录:

  1. 通过删除应用程序中的任何未使用的引用,您可以防止 CLR 通过在运行时加载未使用的引用模块。这意味着您将减少应用程序的启动时间,因为要加载每个模块并避免使用永远不会使用的编译器负载元数据。您可能会发现,根据每个库的大小,您的启动时间明显减少。这并不是说您的应用程序一旦加载会更快,但是知道您的启动时间可能会减少可能非常方便。

  2. 删除任何未使用的参考文献的另一个好处是,您将降低与名称空间冲突的风险。例如,如果您都有 System.DrawingSystem.Web.UI.WebControls 引用,您可能会发现,尝试引用 Image 班级。如果您使用的是匹配这些引用的同类指令,则编译器将无法分辨要使用哪个参考。如果您在开发时定期使用自动完成,则删除未使用的名称空间将减少文本编辑器中的自动完成值的数量。

No effect on execution speed, but there may be some slight effect on compilation speed/intellisense as there are more potential namespaces to search for the proper class. I wouldn't worry too much about it, but you can use the Organize Usings menu item to remove and sort the using statements.

Code that does not execute does not affect the performance of a program.

No, there are several process involved when compiling a program. When the compiler start looking for references (classes, methods) it will use only the ones used on the code. The using directive only tells the compiler where to look. A lot of unused using statement could maybe have a performance issue but just at compile time. At runtime, all the outside code is properly linked or included as part of the binary.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top