Type.GetElementType Method
.NET Framework 3.0
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)
Assembly: mscorlib (in mscorlib.dll)
public abstract Type GetElementType ()
public abstract function GetElementType () : Type
Not applicable.
Return Value
The Type of the object encompassed or referred to by the current array, pointer, or reference type, or 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.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() ); }
import System.*;
class TestGetElementType
{
public static void main(String[] args)
{
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());
} //main
} //TestGetElementType
This code produces the following output:
System.Int32[] element type is System.Int32
TestGetElementType element type is null
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: