Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    A client of the disciplined BankAccount.Lecture 5 - slide 7 : 29
Program 6
using System;

class C{

  public static void Main(){
    BankAccount ba = new BankAccount("Peter", 1000);             
    Console.WriteLine(ba);
    
    ba.Balance += 100;            // read balance + deposit
    Console.WriteLine(ba);
    
    ba.Balance -= 300;            // read balance + withdraw
    Console.WriteLine(ba);
    
    decimal amount = ba.Balance;  // read balance
    ba.Balance = amount + 100;    // deposit
    Console.WriteLine(ba);
    
    ba.Balance = 400;             // illegal deposit
    Console.WriteLine(ba);

  }

}
 
 
 
 
 
From start account is in read mode.
 
One read and one write. Leaves account in reading mode: 
 
 
One read and one write. Leaves account in reading mode:     
 
 
First line: read. Next line: write. Left in reading mode: 
 
 
 
Writing attempted, but account is in reading mode: