Just looking for a quick clarification here. I’m going through the scripting tutorials, and in the namespace lesson, it said that nested namespaces, such as System.Collections, implicitly included the higher-level namespace, as well. (At least, that’s how I interpreted it. I may very well be wrong.)
So, why do some of the other lessons bother including System.Collections.Generic, System.Collections, and System, instead of just using the most nested one? Wouldn’t System.Collections.Generic imply the other two?
Or have I misunderstood the way the namespace nesting works, and you always have to explicitly declare which namespace(s) you want, regardless of nesting? I imagine this is the case, since I don’t see why people would declare both if my first assumption were correct, but I’d like to ask someone who has a better grasp of namespaces than I do.
As far as I understood you’re talking not about including but using only (those are two different things, including term is used for inclusion of dlls and other files), and no that doesn’t work like that. Let’s imagine you have 2 functions FNested and FRoot that lie ~there:
You can call them without using like that:
Now if you say using A you can call them like:
- A.FRoot or FRoot
- A.B.C.FNested or B.C.FNested
if you say using A.B then:
- A.B.C.FNested or C.FNested
if you say using A.B.C and using A then:
- A.FRoot or FRoot
- A.B.C.FNested or B.C.FNested or FNested
It’s basically just to shorten the thing you write, in compiled application there will be completely no benefits of one over another so just go the way you like more.
Also thing to note is that if you have for example A.B.Something and A.Something you won’t really want to write using both A.B and A in same script because they contain function with equal name and compiler will not know which one to use in compile time, but don’t worry you’ll get “ambigous” error so you will know that even before compile.
Thank you. That makes perfect sense.