Type.Namespace プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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
Type の名前空間。現在のインスタンスに名前空間がない場合、または現在のインスタンスがジェネリック パラメーターを表す場合は null
。
次の例では、 および プロパティと の Namespace
メソッドTypeの使用方法をToString示します。Module
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.
名前空間は、論理的なデザイン時の名前付けの利便性であり、主にアプリケーションでスコープを定義し、クラスやその他の型を 1 つの階層構造で整理するために使用されます。 ランタイムの観点からは、名前空間はありません。
現在 Type の が構築されたジェネリック型を表す場合、このプロパティはジェネリック型定義を含む名前空間を返します。 同様に、現在 Type の がジェネリック パラメーター T
を表す場合、このプロパティは を定義するジェネリック型定義を含む名前空間を返します T
。
現在 Type の オブジェクトがジェネリック パラメーターを表し、ジェネリック型定義が使用できない場合 (によって MakeGenericMethodParameter返されるシグネチャ型など) の場合、このプロパティは を返します null
。
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。