开发者

Is there a performance gain in removing unnecessary namespace (using) directives?

开发者 https://www.devze.com 2023-03-31 00:47 出处:网络
Does it matter how many using开发者_运维百科 compiler directives are in my classes? Is there a performance gain in removing those that aren\'t necessary?

Does it matter how many using开发者_运维百科 compiler directives are in my classes? Is there a performance gain in removing those that aren't necessary?

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.

i.e.:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

Thanks!


No, there's no performance advantage.

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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消