Search code examples
c#vb.netlanguage-featuresnamespaces

Is there a way to escape root namespace in VB?


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Text.MyCustom mc = new System.Text.MyCustom();  
        }
    }
}

namespace System.Text
{
    public class MyCustom { }
}

How do I do this in VB, while having a root namespace in the application, is this possible?

Update: According to the answers I assume there ain't no way to do this. I posted a feature suggestion to Microsoft Connect: Please vote.


Solution

  • In VB.NET of VS 2012 this old problem is fixed. Beginning with this version you can escape the root namespace with a leading global. The following code is buggy in VS 2010 and correct in VS 2012:

    Imports Tools
    
    Module Module1
        Sub Main()
            SayHello()
        End Sub
    End Module
    
    Namespace Global.Tools
        Module TestModule
            Sub SayHello()
                Console.Out.WriteLine("Hello")
            End Sub
        End Module
    End Namespace