Use the 'as' operator to perform a safe cast : As : Operator C# Examples


C# Examples » Operator » As »

 

Use the 'as' operator to perform a safe cast









    
using  System;
using  System.IO;

class  MainClass
{
        public  static  void  Main()  
        {
                Object  someObject  =  new  StringReader("This  is  a  StringReader");

                
                StringReader  reader  =  someObject  as  StringReader;
                if  (reader  !=  null)  
                {
                        Console.WriteLine("as:  someObject  is  a  StringReader");
                }
        }
}
    
   
  
   



Output

as: someObject is a StringReader


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» As