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.
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.
In a namespace declaration, Global cannot be nested in another namespace. You can use the Application Page, Project Designer (Visual Basic) to view and modify the Root Namespace of the project. For new projects, the Root Namespace defaults to the project name.
You can also use the Global keyword in a Namespace Statement. This lets you define a namespace out of the root namespace of your project. All namespaces in your project are based on the root namespace for the project. Visual Studio assigns your project name as the default root namespace for all code in your project.
Before getting into some of the other features, be aware that every project is contained in a namespace. VB.NET uses the name of your project (WindowsApplication1 for a standard forms application if you don't change it) as the default namespace.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With