是否值得从我的文件中删除“使用系统”?

时间:2022-04-02 04:06:42

Developing a series of POCOs on my project, and just realized that some of them doesn't need the using System; clause.

在我的项目中开发了一系列POCOs,发现有些不需要使用系统;条款。

Is there any performance or size penalty for leaving unused using <module>; on my objects or project ?

使用 <模块> 不使用是否存在性能或尺寸损失?在我的对象或项目上?

Will my classes get bigger, or slower, or bloated because of this or the compiler/optimizer is smart enough to take care of this?

我的类会变得更大,或者更慢,还是因为这个或者编译器/优化器足够聪明来处理这个问题?

7 个解决方案

#1


5  

no there are not performance issue .

不,没有性能问题。

it is just a readability matter(I would suggest to remove them)

这只是一个可读性问题(我建议删除它们)

more info at: Why should you remove unnecessary C# using directives?

更多信息请访问:为什么要使用指令删除不必要的c# ?

#2


1  

All the "using System;" statement does is allow you to use that namespace without fully qualified names. It doesn't affect run-time performance in any way.

所有“using System;”语句都允许您使用没有完全限定名称的名称空间。它不会以任何方式影响运行时性能。

#3


1  

There is no runtime performance penalty for having unused using statements in your code. They don't appear is the compiled DLL in any form (they do exist in the PDB).

在代码中使用未使用的语句不会对运行时性能造成影响。它们不会以任何形式出现在已编译的DLL中(它们确实存在于PDB中)。

However if you know them to be invalid it's generally considered good style to remove them. Having unused usings is essentially stating a false dependency your code has on a set of types and extension methods.

但是,如果您知道它们是无效的,通常认为删除它们是很好的样式。使用未使用的usings实际上是在说明代码对一组类型和扩展方法的错误依赖。

Determining which usings are not used is a tedious process. I find it's best to just install a tool like PowerCommands and let it do the work on file save.

确定哪些使用没有被使用是一个冗长的过程。我发现最好只安装PowerCommands这样的工具,让它执行文件保存的工作。

#4


0  

That brings neither performance gain nor hit.

这既不会带来性能的提升,也不会带来性能的冲击。

I remove all unused and sort all used usings as code style (neatness). You can do this via Visual Studio context menu (I bound it to a hotkey).

我删除所有未使用的,并将所有使用的作为代码样式(整洁)进行排序。您可以通过Visual Studio上下文菜单(我将它绑定到一个热键)来实现这一点。

#5


0  

If you are not using a reference / assembly or extended functionality for example using System.Linq; by default gets added to VS2010 projects.. if you don't use it.. just remove it.. no performance issues

如果您不使用引用/汇编或扩展功能,例如使用System.Linq;默认情况下,添加到VS2010项目中。如果你不使用它。只是删除. .没有性能问题

#6


0  

The using directive is just syntactic sugar.

使用指令只是语法糖。

Adding using references will not affect performance other than a marginal compile-time difference.

除了边际编译时差异之外,添加引用不会影响性能。

#7


0  

It in no way affects the output of the compiler or the performance of the compiled program!

它不会影响编译器的输出或编译程序的性能!

It can be removed a as part of personal preference. I would personally recommend it as it would make the compilation faster (fewer namespaces for the compiler to look up) and also improve the performance of intellisense.

它可以作为个人偏好的一部分被移除。我个人推荐它,因为它可以使编译速度更快(编译器查找的名称空间更少),还可以提高intellisense的性能。

#1


5  

no there are not performance issue .

不,没有性能问题。

it is just a readability matter(I would suggest to remove them)

这只是一个可读性问题(我建议删除它们)

more info at: Why should you remove unnecessary C# using directives?

更多信息请访问:为什么要使用指令删除不必要的c# ?

#2


1  

All the "using System;" statement does is allow you to use that namespace without fully qualified names. It doesn't affect run-time performance in any way.

所有“using System;”语句都允许您使用没有完全限定名称的名称空间。它不会以任何方式影响运行时性能。

#3


1  

There is no runtime performance penalty for having unused using statements in your code. They don't appear is the compiled DLL in any form (they do exist in the PDB).

在代码中使用未使用的语句不会对运行时性能造成影响。它们不会以任何形式出现在已编译的DLL中(它们确实存在于PDB中)。

However if you know them to be invalid it's generally considered good style to remove them. Having unused usings is essentially stating a false dependency your code has on a set of types and extension methods.

但是,如果您知道它们是无效的,通常认为删除它们是很好的样式。使用未使用的usings实际上是在说明代码对一组类型和扩展方法的错误依赖。

Determining which usings are not used is a tedious process. I find it's best to just install a tool like PowerCommands and let it do the work on file save.

确定哪些使用没有被使用是一个冗长的过程。我发现最好只安装PowerCommands这样的工具,让它执行文件保存的工作。

#4


0  

That brings neither performance gain nor hit.

这既不会带来性能的提升,也不会带来性能的冲击。

I remove all unused and sort all used usings as code style (neatness). You can do this via Visual Studio context menu (I bound it to a hotkey).

我删除所有未使用的,并将所有使用的作为代码样式(整洁)进行排序。您可以通过Visual Studio上下文菜单(我将它绑定到一个热键)来实现这一点。

#5


0  

If you are not using a reference / assembly or extended functionality for example using System.Linq; by default gets added to VS2010 projects.. if you don't use it.. just remove it.. no performance issues

如果您不使用引用/汇编或扩展功能,例如使用System.Linq;默认情况下,添加到VS2010项目中。如果你不使用它。只是删除. .没有性能问题

#6


0  

The using directive is just syntactic sugar.

使用指令只是语法糖。

Adding using references will not affect performance other than a marginal compile-time difference.

除了边际编译时差异之外,添加引用不会影响性能。

#7


0  

It in no way affects the output of the compiler or the performance of the compiled program!

它不会影响编译器的输出或编译程序的性能!

It can be removed a as part of personal preference. I would personally recommend it as it would make the compilation faster (fewer namespaces for the compiler to look up) and also improve the performance of intellisense.

它可以作为个人偏好的一部分被移除。我个人推荐它,因为它可以使编译速度更快(编译器查找的名称空间更少),还可以提高intellisense的性能。