Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

c# - 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?

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...