Share via


Type.GetElementType メソッド

派生クラスによってオーバーライドされた場合、現在の配列、ポインタ、または参照型によって包含または参照されるオブジェクトの Type を返します。

Public MustOverride Function GetElementType() As Type
[C#]
public abstract Type GetElementType();
[C++]
public: virtual Type* GetElementType() = 0;
[JScript]
public abstract function GetElementType() : Type;

戻り値

現在の配列、ポインタ、または参照型によって包含または参照されるオブジェクトの Type

または

現在の Type が配列、ポインタ、または参照渡しでない場合は null 参照 (Visual Basic では Nothing) 。

使用例

[Visual Basic, C#, C++] GetElementType メソッドを使用する例を次に示します。

 
Imports System

Class TestGetElementType

    Public Shared Sub Main()
        Dim array As Integer() = {1, 2, 3}
        Dim t As Type = array.GetType()
        Dim t2 As Type = t.GetElementType()
        Console.WriteLine("The element type of {0} is {1}.", array, t2.ToString())
        Dim newMe As New TestGetElementType()
        t = newMe.GetType()
        t2 = t.GetElementType()
        If t2 Is Nothing Then
            Console.WriteLine("The element type of {0} is {1}.", newMe, "null")
        Else
            Console.WriteLine("The element type of {0} is {1}.", newMe, t2.ToString())
        End If
    End Sub 'Main
End Class 'TestGetElementType

[C#] 
using System;
class TestGetElementType 
{
    public static void Main() 
    {
        int[] array = {1,2,3};
        Type t = array.GetType();
        Type t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.",array, t2.ToString());
        TestGetElementType newMe = new TestGetElementType();
        t = newMe.GetType();
        t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.", newMe, t2==null? "null" : t2.ToString());
    }
}

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

using namespace System;

public __gc class TestGetElementType
{
};

int main() {
   Int32 array[] = {1, 2, 3};
   Type*  t = array->GetType();
   Type*  t2 = t->GetElementType();
   Console::WriteLine(S"The element type of {0} is {1}.", array, t2);
   TestGetElementType* newMe = new TestGetElementType();
   t = newMe->GetType();
   t2 = t->GetElementType();
   Console::WriteLine(S"The element type of {0} is {1}.", newMe, t2==0? S"null" : t2->ToString());
}

[Visual Basic, C#, C++] このコードによって、次の出力が生成されます。

System.Int32[] element type is System.Int32
    TestGetElementType element type is null

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | HasElementType