Cet article a fait l'objet d'une traduction manuelle. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. |
Traduction
Source
|
Type.IsArrayImpl, méthode
.NET Framework 4
Espace de noms :
System
Assembly : mscorlib (dans mscorlib.dll)
Une instance de la classe Array doit retourner false, car il s'agit d'un objet et non d'un tableau.
L'exemple suivant substitue la méthode IsArrayImpl dans la classe MyTypeDelegator, vérifie si une variable est un tableau et affiche le résultat.
using System; using System.Reflection; public class MyTypeDelegator : TypeDelegator { public string myElementType = null; public Type myType; public MyTypeDelegator(Type myType) : base(myType) { this.myType = myType; } // Override IsArrayImpl(). protected override bool IsArrayImpl() { // Determine whether the type is an array. if(myType.IsArray) { myElementType = "array"; return true; } // Return false if the type is not an array. return false; } } public class Type_IsArrayImpl { public static void Main() { try { int myInt = 0 ; // Create an instance of an array element. int[] myArray = new int[5]; MyTypeDelegator myType = new MyTypeDelegator(myArray.GetType()); Console.WriteLine("\nDetermine whether the variable is an array.\n"); // Determine whether myType is an array type. if( myType.IsArray) Console.WriteLine("The type of myArray is {0}.", myType.myElementType); else Console.WriteLine("myArray is not an array."); myType = new MyTypeDelegator(myInt.GetType()); // Determine whether myType is an array type. if( myType.IsArray) Console.WriteLine("The type of myInt is {0}.", myType.myElementType); else Console.WriteLine("myInt is not an array."); } catch( Exception e ) { Console.WriteLine("Exception: {0}", e.Message ); } } }
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.