| | |
Namespaces
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 103
Reputation:
Solved Threads: 17
what will be the impact of what? a performance hit on the program?
pretty much none... you can consider namespaces containers for classes, which don't actually exist in memory in the current program unless you are specifcally "using" that namespace. and in any case, the impact of anything in C# really isn't that bad since C#'s garbage collector is doing all the work for you.
pretty much none... you can consider namespaces containers for classes, which don't actually exist in memory in the current program unless you are specifcally "using" that namespace. and in any case, the impact of anything in C# really isn't that bad since C#'s garbage collector is doing all the work for you.
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
Namespace declarations do not impact the resulting application.
They are used by the pre compiler to locate code addressing during the compile phase. You could preface every object and type in your source code with its namespace, and all you are doing is beating up yourself.
The c# compiler examines each object and type in your source code as it compiles. It searches the namespaces you have declared. IOW, declaring the Namespace's at the top of the code allows you to write code without prepending the correct namespace for each and every object and type.
If you need lets say the name of the PC, and did not add System.Net in your uses section, then doing it this way:
string MyPCname = System.Net.Dns.GetHostName();
would do the same thing as adding System.Net to the using section and just write string MyPCname = Dns.GetHostName(). Just because you add System.Net to the using section does not mean that every method in that name space is included in your compiled application. In either case, the compiler either searched your using section, or used your direct implementation to find the address of Dns.GetHostName().
Using the direct call (inluding the namespace) just saved the pre compiler a search step.... Not you. The resulting application performance is not affected using either method of declaration.
They are used by the pre compiler to locate code addressing during the compile phase. You could preface every object and type in your source code with its namespace, and all you are doing is beating up yourself.
The c# compiler examines each object and type in your source code as it compiles. It searches the namespaces you have declared. IOW, declaring the Namespace's at the top of the code allows you to write code without prepending the correct namespace for each and every object and type.
If you need lets say the name of the PC, and did not add System.Net in your uses section, then doing it this way:
string MyPCname = System.Net.Dns.GetHostName();
would do the same thing as adding System.Net to the using section and just write string MyPCname = Dns.GetHostName(). Just because you add System.Net to the using section does not mean that every method in that name space is included in your compiled application. In either case, the compiler either searched your using section, or used your direct implementation to find the address of Dns.GetHostName().
Using the direct call (inluding the namespace) just saved the pre compiler a search step.... Not you. The resulting application performance is not affected using either method of declaration.
![]() |
Similar Threads
- Ignoring xmlns namespaces in the input xml file (XML, XSLT and XPATH)
- About the namespaces (C++)
- Features in PHP 5 (PHP)
Other Threads in the C# Forum
- Previous Thread: data grid.... very urgent......
- Next Thread: knight's tour problem
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagridview dataset datetime degrees development draganddrop drawing encryption enum excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





