| using System;
class App {
public static void Main(){
BankAccount ba1 = new BankAccount("George", 1000.0M, 0.01),
ba2 = new CheckAccount("Bill", 2000.0M, 0.01),
baRes1, baRes2, baRes3, baRes4, baRes5, baRes6;
CheckAccount ca = new CheckAccount("John", 2000.0M, 0.01);
baRes1 = ba1 as BankAccount;
Report(baRes1);
baRes2 = ba1 as CheckAccount;
Report(baRes2); // null is reported
baRes3 = ba2 as BankAccount;
Report(baRes3);
baRes4 = ba2 as CheckAccount;
Report(baRes4);
baRes5 = ca as BankAccount;
Report(baRes5);
baRes6 = ca as CheckAccount;
Report(baRes6);
}
public static void Report(BankAccount ba){
if (ba != null)
Console.WriteLine("{0}", ba);
else
Console.WriteLine("null");
}
} |