Namespace inheritence difference between VB.NET and C#

Recently, I’ve been involved in a .NET project that uses both VB.NET and C# projects in the same Visual Studio solution. Personally, I prefer C#, but VB.NET isn’t that hard to switch to, except that you can run into an unlogical namespace inconvenience.

VB.NET and C# handle the namespace inheritence in their class files and project files differently :S

VB.NET project

  1. Specify the Root namespace of your project as “Test.VB”
  2. Add the following class to that project:
    Namespace Test.VB.TestNamespace
    Public Class Class1
    'Some code
    End Class
    End Namespace

C# project

  1. Specify the Root namespace of your project as “Test.CS”
  2. Add the following class to your project:
    namespace Test.CS.TestNamespace
    {
    public class Class1
    {
    //Some code
    }
    }

Addressing those classes from your main project in the solution:

Test.CS.TestNamespace.Class1 class1;
Test.VB.Test.VB.TestNamespace.Class1 class2;

As you can see… The VB.NET class inherits the project’s namespace, the C# class doesn’t.