Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
QuestionDuplicate 'using' statements = inefficient ? Pin
nosmij13-May-03 20:09
nosmij13-May-03 20:09 
AnswerRe: Duplicate 'using' statements = inefficient ? Pin
Jon Newman13-May-03 22:06
Jon Newman13-May-03 22:06 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
nosmij13-May-03 23:04
nosmij13-May-03 23:04 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
Jon Newman13-May-03 23:30
Jon Newman13-May-03 23:30 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
nosmij14-May-03 17:42
nosmij14-May-03 17:42 
AnswerRe: Duplicate 'using' statements = inefficient ? Pin
James T. Johnson14-May-03 14:19
James T. Johnson14-May-03 14:19 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
nosmij14-May-03 17:49
nosmij14-May-03 17:49 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
James T. Johnson14-May-03 18:24
James T. Johnson14-May-03 18:24 
nosmij wrote:
how does the compiler keep track of these files

Ok, first we need to get in touch with something Jonny was trying to explain.

A namespace is just a logical grouping construct used by C# (and all other .NET languages) to keep the chances of naming collisions down and to give some sense of order to the framework.

An assembly is a physical grouping construct used by the framework, generally used to keep common functionality together. These usually have a .dll or .exe extension (though others are possible).

A namespace -- since it is a logical grouping construct -- can span multiple assemblies and you can have multiple namespaces in an assembly (you can also have multiple namespaces span multiple assemblies). Another way of thinking of namespaces is that they are prefixes to class names and this is how the .NET Framework treats them.

Unfortunately for us programmers, we get bored if we have to type the namespace before every classname. This is where the using statement comes in. It lets us skip typing the namespace before the class name, if we put that we are using that namespace, enabling us to get on to more important thing.

In order to use a class, you must first reference the assembly it is located in. This, again, has nothing to do with the using statement but is instead something you tell the C# compiler (either through the command-line or by setting options in your IDE). By default the assemblies listed in %WINDIR%\Microsoft.NET\Framework\%VERSION%\csc.rsp will be referenced by the compiler.

A reference means that you may or may not need data out of that assembly, but if you try to use a data type that can't be found, the framework will load the assembly that data type is located in first. You can reference assemblies you don't use, but you must always reference assemblies that you use (whether that reference comes from the csc.rsp or by specifying it manually).

As to optimizations regarding excess references:
If you never use a data type in an assembly, even if it is referenced by the compiler, then you will never load that assembly into memory. Also, if you wrote your code so that you conditionally use a data type out of an assembly, then only if that condition is true will the assembly be loaded.

Hope that makes some sense, if you have any more questions I'll answer them tomorrow I need sleep Sleepy | :zzz:

James

"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation

GeneralRe: Duplicate 'using' statements = inefficient ? Pin
nosmij14-May-03 18:48
nosmij14-May-03 18:48 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
nosmij14-May-03 19:05
nosmij14-May-03 19:05 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
Jon Newman14-May-03 22:56
Jon Newman14-May-03 22:56 
GeneralReally hard question #1 Pin
eggie513-May-03 20:02
eggie513-May-03 20:02 
GeneralRe: Really hard question #1 Pin
Robin Golden14-May-03 2:39
Robin Golden14-May-03 2:39 
GeneralRe: Really hard question #1 Pin
eggie514-May-03 7:52
eggie514-May-03 7:52 
GeneralRe: Really hard question #1 Pin
eggie514-May-03 9:36
eggie514-May-03 9:36 
GeneralRe: Really hard question #1 Pin
James T. Johnson14-May-03 14:13
James T. Johnson14-May-03 14:13 
GeneralRe: Really hard question #1 Pin
eggie514-May-03 16:57
eggie514-May-03 16:57 
GeneralRe: Really hard question #1 Pin
James T. Johnson14-May-03 17:07
James T. Johnson14-May-03 17:07 
GeneralRe: Really hard question #1 Pin
eggie514-May-03 17:46
eggie514-May-03 17:46 
GeneralRe: Really hard question #1 Pin
jeff_martin14-May-03 5:48
jeff_martin14-May-03 5:48 
Generalquestion on format color for DataGrid Pin
cruscal13-May-03 18:14
cruscal13-May-03 18:14 
QuestionResizable control? Pin
Wmzong13-May-03 16:41
Wmzong13-May-03 16:41 
GeneralDataGrid... Row Selection & Column Header Alignment Pin
jmt9n13-May-03 13:28
jmt9n13-May-03 13:28 
Generaliconic child window Pin
Anonymous13-May-03 12:44
Anonymous13-May-03 12:44 
GeneralWindows Form Dialog when Logged Out Pin
Ingram Leedy13-May-03 10:53
Ingram Leedy13-May-03 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.