Having "using" when not necessary, performance hit?

  • Thread starter Thread starter a
  • Start date Start date
A

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.
 
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 said:
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...)
 
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" <[email protected]>
| 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: <[email protected]>
| 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!TK2MSFTNGP09.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.
|
|
|
 
Actually I think the respective assemblies will only be loaded at the time
your code accesses them.

Scarfeet
 
-----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/oPLewEwccQ4rWPgRAlCpAJ9w2lI0cNRZ9wbSDNAffYAEbKMiNwCffbsW
UOSwKswMhRsUyaXYDKXAKgM=
=s5MI
-----END PGP SIGNATURE-----
 
Back
Top