⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bank.cs

📁 csharp-solution,C#高效编程源码
💻 CS
字号:
using System;
using System.Collections;

namespace Banking 
{

/// <summary>
///    Bank acts as a factory for accounts
/// </summary>

public class Bank
{
	private static Hashtable accountStore = new Hashtable();

    private Bank()
    {
        // Constructor is private - Bank is a singleton
    }

	// Factory methods

	public static long CreateAccount()
	{
		BankAccount newAcc = new BankAccount();
		long accNo = newAcc.Number;
		accountStore[accNo] = newAcc;
		return accNo;
	}

	public static long CreateAccount(AccountType accType, decimal balance)
	{
		BankAccount newAcc = new BankAccount(accType, balance);
		long accNo = newAcc.Number;
		accountStore[accNo] = newAcc;
		return accNo;
	}

	public static long CreateAccount(AccountType accType)
	{
		BankAccount newAcc = new BankAccount(accType);
		long accNo = newAcc.Number;
		accountStore[accNo] = newAcc;
		return accNo;
	}

	public static long CreateAccount(decimal balance)
	{
		BankAccount newAcc = new BankAccount(balance);
		long accNo = newAcc.Number;
		accountStore[accNo] = newAcc;
		return accNo;
	}

	public static BankAccount GetAccount(long accNo)
	{
		BankAccount theAcc = (BankAccount)accountStore[accNo];
		return theAcc;
	}

	public static bool CloseAccount(long accNo)
	{
		try {
			BankAccount theAcc = (BankAccount)accountStore[accNo];
			accountStore.Remove(accNo);
			theAcc.Dispose();
			return true;
		} catch {
			return false;
		}
	}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -