Use 'is' to avoid an invalid cast. : Is : Operator C# Examples


C# Examples » Operator » Is »

 

Use 'is' to avoid an invalid cast.









    
using  System;  
  
class  A  {}  
class  B  :  A  {}  
  
class  CheckCast  {  
    public  static  void  Main()  {  
        A  a  =  new  A();  
        B  b  =  new  B();  
  
        if(a  is  B)
            b  =  (B)  a;  
    }  
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» Is