Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Annotated program -- Keyboard shortcut: 't'    bank-account/bank-account-properties/disciplined-bank-account.cs - A BankAccount class with a disciplined Balance property.Lecture 5 - slide 7 : 29
Program 5

using System;

public class BankAccount {

   private string owner;
   private decimal balance;  
   private bool readMode;    

   public BankAccount(string owner, decimal balance) {
      this.owner = owner; 
      this.balance = balance;
      this.readMode = true;
   }

   public decimal Balance {
     get {if (readMode){
             readMode = false;
             return balance;
          }
          else throw new Exception("Cannot read now!");
         }
     set {if (!readMode){
             balance = value;
             readMode = true;
          }
          else throw new Exception("Cannot write now!");
         }
   }   

   public override string ToString() {
      return owner + "'s account holds " +
            + balance + " kroner";
   }
}