Type.Namespace Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the namespace of the Type.
public:
abstract property System::String ^ Namespace { System::String ^ get(); };
public abstract string Namespace { get; }
public abstract string? Namespace { get; }
member this.Namespace : string
Public MustOverride ReadOnly Property Namespace As String
Property Value
The namespace of the Type; null
if the current instance has no namespace or represents a generic parameter.
Implements
Examples
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
{
};
}
void main()
{
Type^ myType = MyNamespace::MyClass::typeid;
Console::WriteLine("Displaying information about {0}:", 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 );
}
// The example displays the following output:
// Displaying information about MyNamespace.MyClass:
// Namespace: MyNamespace
// Module: type_tostring.exe
// Fully qualified name: MyNamespace.MyClass
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.
namespace MyNamespace
type MyClass() = class end
namespace global
module Example =
let myType = typeof<MyNamespace.MyClass>
printfn $"Displaying information about {myType}:"
// Get the namespace of the myClass class.
printfn $" Namespace: {myType.Namespace}."
// Get the name of the ilmodule.
printfn $" Module: {myType.Module}."
// Get the fully qualified type name.
printfn $" Fully qualified name: {myType.ToString()}."
// The example displays the following output:
// Displaying information about MyNamespace.MyClass:
// Namespace: MyNamespace.
// Module: type_tostring.exe.
// Fully qualified name: MyNamespace.MyClass.
Namespace MyNamespace
Class [MyClass]
End Class
End Namespace
Public Class Example
Public Shared Sub Main()
Dim myType As Type = GetType(MyNamespace.MyClass)
Console.WriteLine(", 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())
End Sub
End Class
' The example displays the following output:
' Displaying information about MyNamespace.MyClass:
' Namespace: MyNamespace.
' Module: type_tostring.exe.
' Fully qualified name: MyNamespace.MyClass.
Remarks
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 and a generic type definition is not available, such as for a signature type returned by MakeGenericMethodParameter, this property returns null
.