El método Type.IsArrayImpl() se usa cuando se anula en una clase derivada, implementa la propiedad IsArray y determina si Type es una array.
Sintaxis: bool abstracto protegido IsArrayImpl();
Valor de retorno: este método devuelve verdadero si el Tipo es una array; de lo contrario, es falso .
Los siguientes programas ilustran el uso del método Type.IsArrayImpl() :
Ejemplo 1:
// C# program to demonstrate the // Type.IsArrayImpl() Method using System; using System.Globalization; using System.Reflection; class GFG { // Main Method public static void Main() { // creating and initializing object of MyClass MyClass mytype = new MyClass(typeof(int)); // checking if mytype has any // elementtype or not if (mytype.HasElementType) Console.WriteLine("The type of myArray is {0}.", mytype.elementtype); else Console.WriteLine("myArray is not an array, pointer,"+ "or reference type."); } } // Defining MyClass extended from TypeDelegator public class MyClass : TypeDelegator { // creating and initializing // elementtype with null public string elementtype = null; // creating and initializing // type with null private Type type = null; // Constructor public MyClass(Type type) : base(type) { this.type = type; } // Override Type.IsArrayImpl(). protected override bool IsArrayImpl() { // Determine whether the type is an array. if (type.IsArray) { elementtype = "array"; return true; } // Return false if the type is not // a reference, array, or pointer type. return false; } }
Producción:
myArray is not an array, pointer,or reference type.
Ejemplo 2:
// C# program to demonstrate the // Type.IsArrayImpl() Method using System; using System.Globalization; using System.Reflection; class GFG { // Main Method public static void Main() { // creating and initializing object of MyClass MyClass mytype = new MyClass(typeof(int[,,,, ])); // checking if mytype has // any elementtype or not if (mytype.HasElementType) Console.WriteLine("The type of {0} is array.", mytype.type); else Console.WriteLine("myArray is not an array,"+ "pointer, or reference type."); } } // Defining MyClass extended from TypeDelegator public class MyClass : TypeDelegator { // creating and initializing // elementtype with null public string elementtype = null; // creating and initializing // type with null public Type type = null; // Constructor public MyClass(Type type) : base(type) { this.type = type; } // Override Type.IsArrayImpl(). protected override bool IsArrayImpl() { // Determine whether the // type is an array. if (type.IsArray) { elementtype = "array"; return true; } // Return false if the type is not // a reference, array, or pointer type. return false; } }
Producción:
The type of System.Int32[,,,,] is array.
Referencia:
Publicación traducida automáticamente
Artículo escrito por RohitPrasad3 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA