英語で読む

次の方法で共有


Type.GetElementType メソッド

定義

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

C#
public abstract Type GetElementType();
C#
public abstract Type? GetElementType();

戻り値

現在の配列、ポインター、または参照型によって包含または参照されるオブジェクトの Type。現在の null が配列またはポインターではない場合、参照によって渡されない場合、ジェネリック型やジェネリック型またはジェネリック メソッドの定義の型パラメーターを表している場合は、Type

実装

次の例では、 メソッドの使用方法を GetElementType 示します。

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

/* This code produces the following output:

The element type of System.Int32[] is System.Int32.
The element type of TestGetElementType is null.
 */

注釈

このメソッドは、 クラスの nullArray 返します。

適用対象

製品 バージョン
.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

こちらもご覧ください