Type.Namespace Property
Assembly: mscorlib (in mscorlib.dll)
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 a null reference (Nothing in Visual Basic).
This following example demonstrates a use of the Namespace and Module properties and the ToString method of Type.
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 ); } }
package MyNamespace;
import System.*;
class MyClass
{
} //MyClass
public class Type_ToString_3
{
public static void main(String[] args)
{
try {
Type myType = MyNamespace.MyClass.class.ToType();
Console.WriteLine("\nPrinting the details of {0}.\n", myType);
// Get the namespace of the class Type_ToString_3.
Console.WriteLine("Namespace: {0}.", myType.get_Namespace());
// Get the name of the module.
Console.WriteLine("Module: {0}.", myType.get_Module());
// Get the fully qualified common language runtime namespace.
Console.WriteLine("Fully qualified type: {0}.", myType.ToString());
}
catch (System.Exception e) {
Console.WriteLine("Exception: " + e.get_Message());
}
} //main
} //Type_ToString_3
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.