GetElementType Method

Type.GetElementType Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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)

'Declaration
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 Nothing 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 Nothing for the Array class.

The following example demonstrates using the GetElementType method.



Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim array As Integer() = {1, 2, 3}
      Dim t As Type = array.GetType()
      Dim t2 As Type = t.GetElementType()
      outputBlock.Text &= String.Format("The element type of {0} is {1}.", _
         array, t2.ToString()) & vbCrLf

      Dim newMe As New Example()
      t = newMe.GetType()
      t2 = t.GetElementType()
      If t2 Is Nothing Then
         outputBlock.Text &= String.Format("The element type of {0} is {1}.", newMe, "Nothing") & vbCrLf
      Else
         outputBlock.Text &= String.Format("The element type of {0} is {1}.", newMe, t2.ToString()) & vbCrLf
      End If
   End Sub 
End Class 

' This code produces output similar to the following:
'
'The element type of System.Int32[] is System.Int32.
'The element type of Example is Nothing.


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft