Type.GetElementType Method ()

 

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)

Public MustOverride Function GetElementType As Type

Return Value

Type: System.Type

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.

This method returns null 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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: