as Keyword C# with Example
using System; class BaseClass{} class DerivedClass : BaseClass{} class asKeywordUsing { public static void Main() { BaseClass baseObject = new BaseClass(); DerivedClass derivedObject = new DerivedClass(); if(baseObject is DerivedClass) derivedObject = (DerivedClass) baseObject; else derivedObject = null; if(derivedObject==null) Console.WriteLine("The cast in derivedObject=(DerivedClass)baseObject is NOT allowed."); else Console.WriteLine("The cast in derivedObject=(DerivedClass)baseObject is allowed"); } }