C# Type IsInstanceOfType

Description

Type IsInstanceOfType determines whether the specified object is an instance of the current Type.

Syntax

Type.IsInstanceOfType has the following syntax.


public virtual bool IsInstanceOfType(
  Object o
)

Parameters

Type.IsInstanceOfType has the following parameters.

  • o - The object to compare with the current type.

Returns

Type.IsInstanceOfType method returns true if the current Type is in the inheritance hierarchy of the object represented by o, or if the current Type is an interface that o supports. false if neither of these conditions is the case, or if o is null, or if the current Type is an open generic type (that is, ContainsGenericParameters returns true).

Example

The following example demonstrates the use of the IsInstanceOfType method.


using System;//from w  w w.  j av a 2  s  .c  om
class IsInstanceTest 
{
    public static void Main() 
    {
        int [] array  = new int [10];
        Type arrayType = typeof(Array);
        Console.WriteLine(arrayType.IsInstanceOfType(array));
    }
}

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