Type.GetElementType Metoda

Definicja

W przypadku przesłonięć w klasie pochodnej funkcja zwraca obiekt obejmowany lub określany przez bieżącą Type tablicę, wskaźnik lub typ odwołania.

public:
 abstract Type ^ GetElementType();
public abstract Type GetElementType ();
public abstract Type? GetElementType ();
abstract member GetElementType : unit -> Type
Public MustOverride Function GetElementType () As Type

Zwraca

Type

Obiekt obejmuje lub odwołuje się do bieżącej tablicy, wskaźnika lub typu referencyjnego, jeśli bieżący nie jest tablicą lub wskaźnikiem albo nie jest przekazywany przez odwołanie albo reprezentuje typ ogólny lub parametr typu w definicji typu ogólnego lub metody Type null Type ogólnej.

Implementuje

Przykłady

W poniższym przykładzie pokazano użycie GetElementType metody .

using namespace System;
public ref class TestGetElementType{};

int main()
{
   array<Int32>^array = {1,2,3};
   Type^ t = array->GetType();
   Type^ t2 = t->GetElementType();
   Console::WriteLine( "The element type of {0} is {1}.", array, t2 );
   TestGetElementType^ newMe = gcnew TestGetElementType;
   t = newMe->GetType();
   t2 = t->GetElementType();
   Console::WriteLine( "The element type of {0} is {1}.", newMe, t2 == nullptr ? "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.
 */
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.
 */
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
End Class

' This code produces the following output:
'
'The element type of System.Int32[] is System.Int32.
'The element type of TestGetElementType is null.

Uwagi

Ta metoda zwraca null wartość dla Array klasy .

Dotyczy

Zobacz też