tags:

views:

26

answers:

1

Converting a C# project to VB.NET, C# projects start off with namespace Foo { in each class. Is it possible to have the same behaviour in VB.NET?

The problem is VB.NET already creates a namespace with the project name that is hidden, so if you do Namespace Foo in VB.NET you end up with all your stuff in the namespace Foo.Foo

+3  A: 

Yep. Just clear out the "Root Namespace" textbox in the project settings.

If you are compiling from the command line, don't pass a /rootnamespace: switch to the compiler.

Mehrdad Afshari
Interesting, c# it is named default namespace, and vb Root namespace. I am guessing the difference is that C# will use the default one if none is specified, where as VB will use the root plus whatever you type.
SLC
@SLC: They are different things in C# and VB. In VB, the setting is passed to the *compiler* as the `/rootnamespace:` switch and is prepended to all type names. In C#, it's just a clue for *Visual Studio* to create new type in that namespace (e.g. Add -> New item...). C# compiler won't add namespaces to types. If you remove the namespace in the source file after VS adds it, the default namespace won't have any real effect. To summarize, in C#, everything is in the source file, but in VB, a compiler switch is in effect.
Mehrdad Afshari