Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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 abstract Type GetElementType()

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.


using System;
class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      int[] array = { 1, 2, 3 };
      Type t = array.GetType();
      Type t2 = t.GetElementType();
      outputBlock.Text += String.Format("The element type of {0} is {1}.", 
         array, t2.ToString()) + "\n";

      Example newMe = new Example();
      t = newMe.GetType();
      t2 = t.GetElementType();
      outputBlock.Text += String.Format("The element type of {0} is {1}.", 
         newMe, t2 == null ? "null" : t2.ToString()) + "\n";
   }
}

/* This code produces the following output:

The element type of System.Int32[] is System.Int32.
The element type of Example is null.
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.