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 illustrate the use of Type.IsArrayImpl() Method:
Example 1:
using System;
using System.Globalization;
using System.Reflection;
class GFG {
public static void Main()
{
MyClass mytype = new MyClass( typeof ( int ));
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." );
}
}
public class MyClass : TypeDelegator {
public string elementtype = null ;
private Type type = null ;
public MyClass(Type type)
: base (type)
{
this .type = type;
}
protected override bool IsArrayImpl()
{
if (type.IsArray)
{
elementtype = "array" ;
return true ;
}
return false ;
}
}
|
Output:
myArray is not an array, pointer,or reference type.
Example 2:
using System;
using System.Globalization;
using System.Reflection;
class GFG {
public static void Main()
{
MyClass mytype = new MyClass( typeof ( int [,,,, ]));
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." );
}
}
public class MyClass : TypeDelegator {
public string elementtype = null ;
public Type type = null ;
public MyClass(Type type)
: base (type)
{
this .type = type;
}
protected override bool IsArrayImpl()
{
if (type.IsArray)
{
elementtype = "array" ;
return true ;
}
return false ;
}
}
|
Output:
The type of System.Int32[,,,,] is array.
Reference:
Last Updated :
23 May, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...