using System.Collections.Concurrent;
public static class Memory
public static ConcurrentDictionary<string, long> BankEntities;
public static void Initialize()
Memory.BankEntities = new ConcurrentDictionary<string, long>();
Memory.BankEntities.TryAdd("A123456", 500);
Memory.BankEntities.TryAdd("B123456", 500);
Memory.BankEntities.TryAdd("C123456", 500);
public static void Main()
Console.WriteLine("Input operation command:");
string input = Console.ReadLine();
Console.WriteLine("A123456 Bal: {0}\nB123456 Bal: {1}\nC123456 Bal: {2}", GetBalance("A123456"), GetBalance("B123456"), GetBalance("C123456"));
else if (input.Trim() == "q")
string[] args = input.Split(',');
String fromAcct = args[0];
long fund = Convert.ToInt64(args[2]);
Tuple<int, string> result = transferMoney(fromAcct, toAcct, fund);
Console.WriteLine(result.Item2 + '\n');
public static Tuple<int, string> transferMoney(String fromAccount, String toAccount, long fund)
Tuple<int, string> result = new Tuple<int, string>(-1, "Error");
Console.WriteLine("\nBefore Transfer\n{0} Bal: {1}\n{2} Bal: {3}", fromAccount, GetBalance(fromAccount), toAccount, GetBalance(toAccount));
Console.WriteLine("\nAfter Transfer:\n{0} Bal: {1}\n{2} Bal: {3}", fromAccount, GetBalance(fromAccount), toAccount, GetBalance(toAccount));
result = new Tuple<int, string>(1, "Success");
public static long GetBalance(String accountNo)
if (Memory.BankEntities.ContainsKey(accountNo))
balance = (long)Memory.BankEntities[accountNo];
public static void UpdateBalance(String accountNo, long balance)
if (Memory.BankEntities.ContainsKey(accountNo))
Memory.BankEntities[accountNo] = balance;