469,945 Members | 1,379 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

Having "using" when not necessary, performance hit?

a
Is there a performance hit if I have many "using" statements that are
unnecessary? For example:

using System.Collections;

when nowhere in my code I'm using System.Collections namespace.

I'm really thinking about the default "using" statements put by VS.NET.
Nov 15 '05 #1
5 2794
Hi,
The using directives don't affect the code generated. They used only to
simplify coding and create "shortcuts" to recently used types for C#
compiler (for example: you will write ArrayList instead of
System.Collections.ArrayList, and compiler will know that, it this context,
the ArrayList is System.Collections.ArrayList).
--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"a" <a@a.com> wrote in message news:eg**************@TK2MSFTNGP09.phx.gbl...
Is there a performance hit if I have many "using" statements that are
unnecessary? For example:

using System.Collections;

when nowhere in my code I'm using System.Collections namespace.

I'm really thinking about the default "using" statements put by VS.NET.

Nov 15 '05 #2
a <a@a.com> wrote:
Is there a performance hit if I have many "using" statements that are
unnecessary? For example:

using System.Collections;

when nowhere in my code I'm using System.Collections namespace.

I'm really thinking about the default "using" statements put by VS.NET.


There's no (runtime) performance hit because the compiled binary should
be the same. Compilation may take a tiny bit longer, but not
noticeably. Consider removing them anyway for the sake of readability
though. (Oh for Eclipse and its "Organize Imports" feature...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

Hi ,

The using statement does not generate redundant code in the exe file.
Also, it will not generate redundant metadata in manifest.(You can check
this through iLdasm.exe)
The using statement just expose certain dll's metadata information to your
application, so that the compiler can recognize the class and members.
Also, the compiler can generate intellisence for you.

I think you can make sure the "no generate redundant code" by checking the
file size between many "using" file and remove "using" file.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "a" <a@a.com>
| Subject: Having "using" when not necessary, performance hit?
| Date: Wed, 29 Oct 2003 23:31:44 -0800
| Lines: 10
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <eg**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: d206-116-117-170.bchsia.telus.net 206.116.117.170
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:195287
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Is there a performance hit if I have many "using" statements that are
| unnecessary? For example:
|
| using System.Collections;
|
| when nowhere in my code I'm using System.Collections namespace.
|
| I'm really thinking about the default "using" statements put by VS.NET.
|
|
|

Nov 15 '05 #4
Actually I think the respective assemblies will only be loaded at the time
your code accesses them.

Scarfeet

"a" <a@a.com> schrieb im Newsbeitrag
news:eg**************@TK2MSFTNGP09.phx.gbl...
Is there a performance hit if I have many "using" statements that are
unnecessary? For example:

using System.Collections;

when nowhere in my code I'm using System.Collections namespace.

I'm really thinking about the default "using" statements put by VS.NET.

Nov 15 '05 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wonder if this will be a feature in the next VS.NET. I'll second a
feature request like this with all my heart :)

Jon Skeet [C# MVP] wrote:

| though. (Oh for Eclipse and its "Organize Imports" feature...)

- --
Ray Hsieh (Ray Djajadinata) [SCJP, SCWCD]
ray underscore usenet at yahoo dot com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQE/oPLewEwccQ4rWPgRAlCpAJ9w2lI0cNRZ9wbSDNAffYAEbKMiNw CffbsW
UOSwKswMhRsUyaXYDKXAKgM=
=s5MI
-----END PGP SIGNATURE-----

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Giles Brown | last post: by
43 posts views Thread by markryde | last post: by
6 posts views Thread by OriginalBrownster | last post: by
reply views Thread by Joe Strout | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.