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.
Assembly: mscorlib (in mscorlib.dll)
Return Value
Type: System.TypeThe 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.
The following example demonstrates using the GetElementType method.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
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.
Show:
Note: