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?
虽然我喜欢编写精简的代码,但有时代码段会被修改,并且没有机会回去检查所有包含的命名空间是否真的有必要.或者,我不会返回并删除那些由 Visual Studio 自动插入的内容.
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.
即:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
谢谢!
推荐答案
不,没有性能优势.
编译器不会为 using 语句生成 IL(可执行代码).IL 仅针对那些利用您提供的 using 语句的类、方法调用等生成.
The compiler doesn't generate IL (executable code) for using statements. IL is only generated for those classes, method calls, etc. that take advantage of the using statements you provide.
因此,未使用的 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.
这篇关于删除不必要的命名空间(使用)指令是否有性能提升?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:删除不必要的命名空间(使用)指令是否有性能提升?
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
