Object Oriented Programming using C#
Generic Collections and how to Serialize them
The code for the Bank class is identical apart from the firs few lines which creates a typed HashSet instead of a typed List.
class Bank
{
private HashSet<Account> accounts;
public HashSet<Account> Accounts
{
get { return accounts;}
}
public Bank()
{
accounts = new HashSet<Account>();
}
public void AddAccount(Account account)
{
accounts.Add(account);
}
public Account GetAccount(String name,String dob)
{
Account FoundAccount = null;
foreach (Account a in accounts)
{
if ((a.Name == name) && (a.DateOfBirth==dob))
{
FoundAccount = a;
}
}
return FoundAccount;
}
}