Updated: September 2009
Gets the namespace of the Type.
Namespace:
System
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public MustOverride ReadOnly Property Namespace As String
Dim instance As Type
Dim value As String
value = instance.Namespace
public abstract string Namespace { get; }
public:
virtual property String^ Namespace {
String^ get () abstract;
}
public abstract function get Namespace () : String
Property Value
Type:
System..::.StringThe namespace of the Type; nullNothingnullptra null reference (Nothing in Visual Basic) if the current instance has no namespace, or represents a generic parameter.
Implements
_Type..::.Namespace
A namespace is a logical design-time naming convenience, used mainly to define scope in an application and organize classes and other types in a single hierarchical structure. From the viewpoint of the runtime, there are no namespaces.
If the current Type represents a constructed generic type, this property returns the namespace that contains the generic type definition. Similarly, if the current Type represents a generic parameter T, this property returns the namespace that contains the generic type definition that defines T.
If the current Type object represents a generic parameter, this property returns nullNothingnullptra null reference (Nothing in Visual Basic).
This following example demonstrates a use of the Namespace and Module properties and the ToString method of Type.
Imports System
Imports Microsoft.VisualBasic
Namespace MyNamespace
Class [MyClass]
End Class '[MyClass]
End Namespace 'MyNamespace
Public Class Type_ToString_3
Public Shared Sub Main()
Try
Dim myType As Type = GetType(MyNamespace.MyClass)
Console.WriteLine(ControlChars.NewLine + "Printing the details of {0}." + ControlChars.NewLine, myType)
' Get the namespace of the class Type_ToString_3.
Console.WriteLine("Namespace: {0}.", myType.Namespace)
' Get the name of the module.
Console.WriteLine("Module: {0}.", myType.Module)
' Get the fully qualified common language runtime namespace.
Console.WriteLine("Fully qualified type: {0}.", myType.ToString())
Catch e As Exception
Console.WriteLine("Exception: " + e.Message.ToString())
End Try
End Sub 'Main
End Class 'Type_ToString_3
using System;
namespace MyNamespace
{
class MyClass
{
}
}
public class Type_ToString_3
{
public static void Main()
{
try
{
Type myType = typeof(MyNamespace.MyClass);
Console.WriteLine("\nPrinting the details of {0}.\n", myType);
// Get the namespace of the class Type_ToString_3.
Console.WriteLine("Namespace: {0}.", myType.Namespace);
// Get the name of the module.
Console.WriteLine("Module: {0}.", myType.Module);
// Get the fully qualified common language runtime namespace.
Console.WriteLine("Fully qualified type: {0}.", myType.ToString());
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message );
}
}
}
using namespace System;
namespace MyNamespace
{
ref class MyClass{};
}
int main()
{
try
{
Type^ myType = MyNamespace::MyClass::typeid;
Console::WriteLine( "\nPrinting the details of {0}.\n", myType );
// Get the namespace of the class MyClass.
Console::WriteLine( "Namespace: {0}.", myType->Namespace );
// Get the name of the module.
Console::WriteLine( "Module: {0}.", myType->Module );
// Get the fully qualified common language runtime namespace.
Console::WriteLine( "Fully qualified type: {0}.", myType );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: {0}", e->Message );
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference
Other Resources
Date | History | Reason |
|---|
September 2009
| Noted that nullNothingnullptra null reference (Nothing in Visual Basic) is returned if the current type has no namespace. |
Customer feedback.
|