public static void Main()
Employee emp1 = new Employee {ID=1, FirstName="Kapil", LastName="Sharma"};
Console.WriteLine("------------------------------------------------");
Console.WriteLine("--Base Class canNOT be cast to Derived Class----");
PermanentEmployee emp2= emp1 as PermanentEmployee;
Console.WriteLine("PermanentEmployee emp2 is NULL");
Console.WriteLine("PermanentEmployee emp2 is NOT NULL");
ContractEmployee emp3= emp1 as ContractEmployee;
Console.WriteLine("ContractEmployee emp3 is NULL");
Console.WriteLine("ContractEmployee emp3 is NOT NULL");
Console.WriteLine("------------------------------------------------");
Console.WriteLine("--Base Class Reference Variable pointing to a Derived Class Object can be cast to Base Class----");
Employee emp4 = new PermanentEmployee {ID=1, FirstName="Kapil", LastName="Sharma"};
PermanentEmployee emp5 = emp4 as PermanentEmployee;
Console.WriteLine("PermanentEmployee emp5 is NULL");
Console.WriteLine("PermanentEmployee emp5 is NOT NULL");
ContractEmployee emp6 = emp4 as ContractEmployee;
Console.WriteLine("ContractEmployee emp6 is NULL");
Console.WriteLine("ContractEmployee emp6 is NOT NULL");
Console.WriteLine("------------------------------------------------");
Console.WriteLine("--Casting Derived type to Base Type is possible----");
PermanentEmployee emp7 = new PermanentEmployee {ID=1, FirstName="Kapil", LastName="Sharma"};
ContractEmployee emp8 = new ContractEmployee {ID=2, FirstName="Bornita", LastName="Das"};
Employee emp9 =emp7 as Employee;
Console.WriteLine("Employee emp9 is NULL");
Console.WriteLine("Employee emp9 is NOT NULL");
Employee emp10 =emp8 as Employee;
Console.WriteLine("Employee emp10 is NULL");
Console.WriteLine("Employee emp10 is NOT NULL");
public int ID {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
class PermanentEmployee: Employee
public int AnnualSalary{get; set;}
class ContractEmployee: Employee
public int MonthlyRate {get; set;}