Name space solution

bullsquad

Member
Joined
Apr 8, 2010
Messages
6
Programming Experience
3-5
I am new to .NET with Java back ground. Got a question on name space. I believe they are synonymous to Java packages concept.

If I need two classes in the same name space do I have to declare the name space in both the classes?. Both classes are in different files

E.g: If Class1 and Class2 need to be in Namespace myspace. Should it be

VB.NET:
Namespace myspace
  Public Class1
End Namespace 

Namespace myspace
   Public Class2
End Namespace
 
Yes I believe that is correct (assuming you did the full class rather than just the signature, but I'm sure you've just done that to save space/time)
 
You can set Root Namespace in Project properties (Application tab), this defaults to the name of the project, and will be the (root) namespace for all classes in project. Explained in help topic Namespace Statement
 
Thanks. I do have the namespace on my project name but i need to divide my classes into 3 different types.

Is there a way to declare 3 namespaces once and include the classes in them instead of declaring namespace is each class?
 
You can more than one class definition within a Namespace block.
 
I am aware of that but that would mean I have to cramp all my classes in one file which is not a good design for maintaining and debugging.
 
Back
Top