Demonstrate is : Operator is as « Language Basics « C# / C Sharp






Demonstrate is

Demonstrate is
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// Demonstrate is. 
 
using System; 
 
class A {} 
class B : A {} 
 
public class UseIs { 
  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"); 
  } 
}


           
       








Related examples in the same category

1.Illustrates the use of the is operatorIllustrates the use of the is operator
2.Test is and asTest is and as
3.Use is to avoid an invalid castUse is to avoid an invalid cast
4.Demonstrate asDemonstrate as
5.Operators and Expressions:Type operators:Is
6.Interfaces:The As OperatorInterfaces:The As Operator