C# Type IsArrayImpl

Description

Type IsArrayImpl when overridden in a derived class, implements the IsArray property and determines whether the Type is an array.

Syntax

Type.IsArrayImpl has the following syntax.


protected abstract bool IsArrayImpl()

Returns

Type.IsArrayImpl method returns true if the Type is an array; otherwise, false.

Example

The following example overrides the IsArrayImpl method in the MyTypeDelegator class, checks if a variable is an array, and displays the result.


using System;// www  .j a va 2  s.  co  m
using System.Reflection;
public class MyTypeDelegator : TypeDelegator
{
    public string myElementType = null;
    public Type myType;
    public MyTypeDelegator(Type myType) : base(myType)
    {
        this.myType = myType;
    }
    protected override bool IsArrayImpl()
    {
        if(myType.IsArray)
        {
            myElementType = "array";
            return true;
        }
        return false;  
    }
}
public class Type_IsArrayImpl
{
    public static void Main()
    {
        int myInt = 0 ; 
        int[] myArray = new int[5];
        MyTypeDelegator myType = new MyTypeDelegator(myArray.GetType());

        Console.WriteLine(myType.IsArray);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version