Type.Namespace 属性

获取 Type 的命名空间。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
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;
}
/** @property */
public abstract String get_Namespace ()
public abstract function get Namespace () : String

属性值

Type 的命名空间,或者为 空引用(在 Visual Basic 中为 Nothing)(如果当前实例表示泛型参数)。

备注

命名空间是一种逻辑上的设计时命名的简便方法,主要用于在应用程序中定义范围或在单层次结构中组织类和其他类型。从运行时的角度来看,不存在命名空间。

如果当前 Type 表示构造泛型类型,则此属性将返回包含泛型类型定义的命名空间。类似地,如果当前 Type 表示泛型参数 T,则此属性返回包含定义 T 的泛型类型定义的命名空间。

如果当前 Type 对象表示泛型参数,则此属性返回 空引用(在 Visual Basic 中为 Nothing)。

示例

下面的示例说明如何使用 TypeNamespaceModule 属性 (Property) 以及 ToString 方法。

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 );
   }
}
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 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Type 类
Type 成员
System 命名空间
String 类
Type.FullName 属性
Type.AssemblyQualifiedName 属性

其他资源

指定完全限定的类型名称