Reputation:
VB.NET automatically prefixes the root namespace set in the project properties to the namespace of each class. This is different from C#, where the full namespace must be declared each time.
Is it possible to override this behaviour, creating a namespace outside of the root namespace?
Upvotes: 16
Views: 8848
Reputation: 3857
If I understand you correctly you just need to set a blank namespace in the project properties dialog and then set namespaces within each source file using Begin/End Namespace commands.
From VS2012 onwards it's possible to get around this, see stackoverflow.com/a/17360357/233095
Upvotes: 12
Reputation: 104712
They now implemented it:
Namespace Global.MyNamespace
End Namespace
Upvotes: 5
Reputation: 36438
Defining the default for the project as blank and then taking total control in each class allows you to do what c# does. However certain project types (Library I believe) do not allow you to change the default namespace to blank.
Use of the Global keyword does not allow you to jump out of the root namespace either: http://msdn.microsoft.com/en-us/library/16czfx55.aspx
Upvotes: 5
Reputation: 38455
You can change the namespace of the entire project by going to properties on the project. else you will have to have a empty root namespace and set the name space in each file with the
Namespace test
class.....
End Namespace
Upvotes: 4