Use the 'as' operator to perform a safe cast : as « Operator « C# / CSharp Tutorial






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");
        }
    }
}
as: someObject is a StringReader








3.13.as
3.13.1.Using as
3.13.2.The As Operator for custom class type
3.13.3.Use the 'as' operator to perform a safe cast
3.13.4.as operator in class hearchy