Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          bank-account/inheritance-2/ex3.cs - An illustration of type conversion with v as C.Lecture 7 - slide 34 : 40
Program 4

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");
  }

}