is operator in class hiearchy : is « Operator « C# / CSharp Tutorial






using System; 
 
class A {} 
class B : A {} 
 
class MainClass { 
  public static void Main() { 
    A a = new A(); 
    B b = new B(); 
 
    if(a is A) 
       Console.WriteLine("a is an A"); 
    if(b is A)  
      Console.WriteLine("b is an A because it is derived from A"); 
    if(a is B)  
      Console.WriteLine("This won't display -- a not derived from B"); 
    if(b is B) 
      Console.WriteLine("B is a B"); 
    if(a is object) 
      Console.WriteLine("a is an object"); 
  } 
}
a is an A
b is an A because it is derived from A
B is a B
a is an object








3.12.is
3.12.1.Type operators: Is
3.12.2.is operator in class hiearchy
3.12.3.Use 'is' to avoid an invalid cast.
3.12.4.Working with Interfaces: is operator
3.12.5.Test if someObject is, or is derived from, a TextReader using the is operator
3.12.6.'is' operator for value data type: int, long and float
3.12.7.Use is in Console.WriteLine