Type.GetElementType Type.GetElementType Type.GetElementType Type.GetElementType Method

Definición

Cuando se invalida en una clase derivada, devuelve la clase Type del objeto englobado o al que hace referencia la matriz, el puntero o el tipo de referencia actual.When overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.

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

Devoluciones

Type del objeto englobado o al que hace referencia la matriz, puntero o tipo de referencia actual; o bien, null si el objeto Type actual no es una matriz o un puntero, o si no se pasa por referencia, o si representa un tipo genérico o un parámetro de tipo en la definición de un tipo genérico o de un método genérico.The Type of the object encompassed or referred to by the current array, pointer, or reference type, or null if the current Type is not an array or a pointer, or is not passed by reference, or represents a generic type or a type parameter in the definition of a generic type or generic method.

Implementaciones

Ejemplos

En el ejemplo siguiente se muestra GetElementType cómo utilizar el método.The following example demonstrates using the GetElementType method.

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 'Main
End Class 'TestGetElementType

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

Comentarios

Este método devuelve null para la Array clase.This method returns null for the Array class.

Se aplica a

Consulte también: