Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    A BankAccount class with a trivial Balance property together with Deposit and Withdraw methods.Lecture 5 - slide 7 : 29
Program 1
using System;

public class BankAccount {

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

   public decimal Balance {   
     get {return balance;}
   }       

   public void Deposit(decimal amount){
     balance += amount;
   } 

   public void Withdraw(decimal amount){
     balance -= amount;
   } 

   public override string ToString() { 
      return owner + "'s account holds " +
            + balance + " kroner";
   }
} 
 
 
 
 
 
The instance variable balance.
Coding style: starts with lower case letter.
 
 
 
 
 
A trivial property (getter).
Coding style: starts with upper case letter.