using System.Collections.Generic;
namespace Encapsulation_car
public BankAccount(string name, double balance)
if (balance < 0) throw new Exception("you're poor");
AllBankAccounts.Add(this);
public void TransferFrom(double money, BankAccount other)
if (money < 0) throw new Exception("Money cannot be negative!");
if (money > other.Balance) throw new Exception("Insufficient funds!");
public void TransferTo(double money, BankAccount other)
if (money < 0) throw new Exception("Money cannot be negative!");
if (money > Balance) throw new Exception("Insufficient funds!");
Console.WriteLine($"{Name} has {Balance}");
public static void PrintAllAccounts()
for (var i = 0; i < AllBankAccounts.Count; i++)
AllBankAccounts[i].Print();
public string Name { get; }
public double Balance { get; private set; }
public static List<BankAccount> AllBankAccounts { get; } = new List<BankAccount>();
static void Main(string[] args)
var BankAccount2 = new BankAccount("luke",1000);
var BankAccount = new BankAccount("jojo",500);
var BankAccount3 = new BankAccount("noah", 200);
BankAccount.PrintAllAccounts();