Type.Namespace Property
Gets the namespace of the Type.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.StringThe namespace of the Type; null if the current instance has no namespace or represents a generic parameter.
Implements
_Type.NamespaceA 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 null.
This following example demonstrates a use of the Namespace and Module properties and the ToString method of Type.
using System; namespace MyNamespace { class MyClass { } } public class Example { public static void Main() { Type myType = typeof(MyNamespace.MyClass); Console.WriteLine("Displaying information about {0}:", myType); // Get the namespace of the myClass class. Console.WriteLine(" Namespace: {0}.", myType.Namespace); // Get the name of the module. Console.WriteLine(" Module: {0}.", myType.Module); // Get the fully qualified type name. Console.WriteLine(" Fully qualified name: {0}.", myType.ToString()); } } // The example displays the following output: // Displaying information about MyNamespace.MyClass: // Namespace: MyNamespace. // Module: type_tostring.exe. // Fully qualified name: MyNamespace.MyClass.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.