When overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.
Namespace:
System
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public MustOverride Function GetElementType As Type
Dim instance As Type
Dim returnValue As Type
returnValue = instance.GetElementType()
public abstract Type GetElementType()
public:
virtual Type^ GetElementType() abstract
public abstract function GetElementType() : Type
Return Value
Type:
System..::.TypeThe Type of the object encompassed or referred to by the current array, pointer, or reference type, or nullNothingnullptra 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.
Implements
_Type..::.GetElementType()()()
This method returns nullNothingnullptra null reference (Nothing in Visual Basic) for the Array class.
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.
*/
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference