EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

Type.GetElementType Method

April 12, 2014

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.
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Cela vous a-t-il été utile ?
(1500 caractères restants)
Merci pour vos suggestions.
Afficher:
© 2014 Microsoft. Tous droits réservés.