C# | Type.HasElementTypeImpl() Method Last Updated : 22 May, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Type.HasElementTypeImpl() Method is used when overridden in a derived class, implementing the HasElementType property and determines whether the current Type encompasses or refers to another type. It means this method checks whether the current Type is an array, a pointer, or is passed by reference. Syntax: protected abstract bool HasElementTypeImpl (); Return Value: This method returns true if the Type is an array, a pointer, or is passed by reference otherwise, false. Below programs illustrate the use of Type.HasElementTypeImpl() Method: Example 1: csharp // C# program to demonstrate the // Type.HasElementTypeImpl() 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.HasElementTypeImpl(). protected override bool HasElementTypeImpl() { // Determine whether the type is an array. if (type.IsArray) { elementtype = "array"; return true; } // Determine whether the type is a reference. if (type.IsByRef) { elementtype = "reference"; return true; } // Determine whether the type is a pointer. if (type.IsPointer) { elementtype = "pointer"; return true; } // Return false if the type is not // a reference, array, or pointer type. return false; } } Output: myArray is not an array, pointer, or reference type. Example 2: csharp // C# program to demonstrate the // Type.HasElementTypeImpl() 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 {1} is {0}.", mytype.elementtype, mytype.type); else Console.WriteLine("{0} is not an array, pointer, or reference type.", mytype.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.HasElementTypeImpl(). protected override bool HasElementTypeImpl() { // Determine whether the type is an array. if (type.IsArray) { elementtype = "array"; return true; } // Determine whether the type is a reference. if (type.IsByRef) { elementtype = "reference"; return true; } // Determine whether the type is a pointer. if (type.IsPointer) { elementtype = "pointer"; return true; } // Return false if the type is not a // reference, array, or a pointer type return false; } } Output: The type of System.Int32[,,,,,,] is array. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.type.haselementtypeimpl?view=netframework-4.8 Comment More infoAdvertise with us Next Article C# | Type.GetTypeHandle() Method R rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp-Type-Class Similar Reads C# | Type.GetElementType() Method Type.GetElementType() Method is used to return the Type of the object encompassed or referred to by the current array, pointer or reference type when overridden in a derived class. Syntax: public abstract Type GetElementType (); Return Value: This method returns the Type of the object encompassed or 2 min read C# | Type.GetNestedType() Method Type.GetNestedType() Method is used to get a specific type nested within the current Type. There are 2 methods in the overload list of this method as follows: GetNestedType(String, BindingFlags) Method GetNestedType(String) Method GetNestedType(String, BindingFlags) Method This method is used to sea 4 min read C# | Type.GetTypeHandle() Method Type.GetTypeHandle() Method is used to get the handle for the Type of a specified object. Syntax: public static RuntimeTypeHandle GetTypeHandle (object o); Here, it takes the object for which to get the type handle. Return Value: This method returns The handle for the Type of the specified Object. E 2 min read C# | Type.IsArrayImpl() Method Type.IsArrayImpl() Method is used when overridden in a derived class, implements the IsArray property and determines whether the Type is an array. Syntax: protected abstract bool IsArrayImpl (); Return Value: This method returns true if the Type is an array otherwise, false. Below programs illustrat 3 min read C# | Type.GetTypeFromHandle() Method Type.GetTypeFromHandle() Method is used to get the type referenced by the specified type handle. Syntax: public static Type GetTypeFromHandle (RuntimeTypeHandle handle); Here, it takes the object which refers to the type. Return Value: This method returns the type referenced by the specified Runtime 2 min read C# | Type.GetTypeCode() Method Type.GetTypeCode() Method is used to get the underlying type code of the specified Type. Syntax: public static TypeCode GetTypeCode (Type type); Here, it takes the type whose underlying type code to get. Return Value: This method returns the code of the underlying type, or Empty if type is null. Bel 2 min read Like