Type.GetElementType Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Cuando se invalida en una clase derivada, devuelve el Type del objeto abarcado o al que hace referencia la matriz actual, el puntero o el tipo de referencia.
public:
abstract Type ^ GetElementType();
public abstract Type GetElementType();
public abstract Type? GetElementType();
abstract member GetElementType : unit -> Type
Public MustOverride Function GetElementType () As Type
Devoluciones
Type del objeto abarcado o al que hace referencia la matriz actual, el puntero o el tipo de referencia, o null si el objeto actual Type no es una matriz o un puntero, o no se pasa por referencia, o representa un tipo genérico o un parámetro de tipo en la definición de un tipo genérico o un método genérico.
Implementaciones
Ejemplos
En el ejemplo siguiente se muestra el uso del GetElementType método .
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.
*/
type TestGetElementType() = class end
do
let array = [| 1; 2; 3 |]
let t = array.GetType()
let t2 = t.GetElementType()
printfn $"The element type of {array} is {t2}."
let newMe = TestGetElementType()
let t = newMe.GetType()
let t2 = t.GetElementType()
printfn $"""The element type of {newMe} is {if t2 = null then "null" else string t2}."""
(* 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.
Comentarios
Este método devuelve null para la Array clase .