When overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.
Assembly: mscorlib (in mscorlib.dll)
Syntax . . :: . Type
The Type of the object encompassed or referred to by the current array, pointer, or reference type, ornull Nothing nullptr a null reference (Nothing in Visual Basic) 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.
. . :: . GetElementType() () ()
Public MustOverride Function GetElementType As Typepublic abstract Type GetElementType()public:
virtual Type^ GetElementType() abstractabstract GetElementType : unit -> Type
Return Value
Type: SystemThe Type of the object encompassed or referred to by the current array, pointer, or reference type, or
Implements
_Type Remarks
This method returns
Examples
The following example demonstrates using the GetElementType method.
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
' 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.
*/
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.
*/
Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.