tags:

views:

43

answers:

3

I read that way back programmers have to think of special names for their classes in order to do not conflict with another one when the file got loaded on users PC. That is what I do not understand, if the class was within e.g. DLL, how it could collide with other class on that PC?

Even without namespaces, if I import a DLL, I guess I would need to call the class from that DLL so I could not make the code impossible to complile. I would really appreciate explanation here, thanks!

A: 

DLL Hell, the Inside Story is a good summary of the old issues - C# addressed this issuer per design - so you do not need to worry anymore.

weismat
A: 

Consider if there are no namespaces. Then you load a type MyClass from an assembly. Now if you load another type from another assembly and there is a MyClass in there. How do you load the second type? How to do tell the compiler which one you want when you say

MyClass o = new MyClass() 

The answer - you have to name namespaces to uniquely identify the class, otherwise it's ambiguous. So you say why not limit the name space to the assembly. This is fine, however it appears that is such a great idea that the designers of the platform introduced a concept where anyone can create multiple namespaces within an assembly to allow people to partition their code better. Then we ask why not allow namespaces to go across assemblies so that we can partition the code more easily.

You have many uses for namespaces and it's upto you the app designer to come up with something that works for you - even if its only one namespace.

Preet Sangha
Well so I can kinda write my own Random class or List class in my namespace and then I will need the original ones qualify with full names, right?
CuriousOne
of course. That's exactly right!
Preet Sangha
Thanks, I now I understand
CuriousOne
+1  A: 

example: System.Drawing.Point and System.Windows.Point

So if a program references both assemblies, without the namespaces, the compiler will get confused when you declare Point p; or Point p = new Point(1,1);, for example

Louis Rhys
But if you use both namespaces and write Point in your code, which one is picekd? How it will now
CuriousOne
if you use both namespaces, you must use full names, i.e. `System.Drawing.Point p = System.Drawing.Point(1,1);`
Louis Rhys