Export (0) Print
Expand All

Type.Namespace Property

Gets the namespace of the Type.

[Visual Basic]
Public MustOverride ReadOnly Property Namespace As String
[C#]
public abstract string Namespace {get;}
[C++]
public: __property virtual String* get_Namespace() = 0;
[JScript]
public abstract function get Namespace() : String;

Property Value

The namespace of the Type.

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.

Example

[Visual Basic, C#, C++] This following example demonstrates a use of the Namespace and Module properties and the ToString method of Type.

[Visual Basic] 
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

[C#] 
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 ); 
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;

namespace MyNamespace {
   __gc class MyClass {
   };
}

int main() {
   try {
      Type*  myType = __typeof(MyNamespace::MyClass);
      Console::WriteLine(S"\nPrinting the details of {0}.\n", myType);
      // Get the namespace of the class MyClass.
      Console::WriteLine(S"Namespace: {0}.", myType->Namespace);
      // Get the name of the module.
      Console::WriteLine(S"Module: {0}.", myType->Module);
      // Get the fully qualified common language runtime namespace.
      Console::WriteLine(S"Fully qualified type: {0}.", myType);
   } catch (Exception* e) {
      Console::WriteLine(S"Exception: {0}", e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | String | FullName | AssemblyQualifiedName | Specifying Fully Qualified Type Names

Show:
© 2014 Microsoft