Type.Namespace Type.Namespace Type.Namespace Type.Namespace Property

定义

获取 Type 的命名空间。Gets the namespace of the Type.

public:
 abstract property System::String ^ Namespace { System::String ^ get(); };
public abstract string Namespace { get; }
member this.Namespace : string
Public MustOverride ReadOnly Property Namespace As String

属性值

Type 的命名空间;如果当前实例没有命名空间或表示泛型参数,则为 nullThe namespace of the Type; null if the current instance has no namespace or represents a generic parameter.

实现

示例

下面的示例演示的一种用法NamespaceModule属性和ToString方法的TypeThis 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
    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.

注解

命名空间是逻辑设计时命名方便起见,主要用于应用程序中定义作用域和组织类和单个层次结构中的其他类型。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.

如果当前Type表示构造的泛型类型,则此属性返回包含泛型类型定义的命名空间。If the current Type represents a constructed generic type, this property returns the namespace that contains the generic type definition. 同样,如果当前Type表示泛型参数T,此属性返回包含定义泛型类型定义的命名空间TSimilarly, if the current Type represents a generic parameter T, this property returns the namespace that contains the generic type definition that defines T.

如果当前Type对象表示泛型参数,则此属性返回nullIf the current Type object represents a generic parameter, this property returns null.

适用于

另请参阅