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
134 views
in Technique[技术] by (71.8m points)

c# - overhead to unused "using" declarations?

I've just installed resharper and it's letting me know the namespaces i'm not actually using in each of my classes.

which lead me to the question - is there actually any overhead in leaving these, unused, using declarations in?

is it just a matter of tight code, or is there a performance hit in invoking these namespaces when i don't need to?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

From The C# Team's answers to frequently asked questions:

When you add assembly references or make use of the 'using' keyword, csc.exe will ignore any assembly which you have not actually made use of in your code ... Don't [waste] your time stripping out unused 'using' statements or assembly references from your application. The C# compiler will do so for you automatically.

You can verify that this is actually the case by calling Assembly.GetReferencedAssemblies(); you'll see that anything that isn't used won't actually be included in the list.

The main utility in stripping out unused ones is

  • It is easier to see what your code is actually using
  • It will keep your Intellisense from being polluted with things that you aren't actually going to use.

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

...