static void Main(string[] args) { Balancer balance = Balancer.getInstance(); balance.Display(); Balancer balance2 = Balancer.getInstance(); balance2.Display(); Balancer balance3 = Balancer.getInstance(); balance3.Display(); Balancer balance4 = Balancer.getInstance(); balance4.Display(); Balancer balance5 = Balancer.getInstance(); balance5.Display(); Balancer balance6 = Balancer.getInstance(); balance6.Display(); }
public static Balancer getInstance() { if (Instance1 == null) { Instance1 = new Balancer(1); amount++; return(Instance1); } else if (Instance2 == null) { Instance2 = new Balancer(2); amount++; return(Instance2); } else if (Instance3 == null) { Instance3 = new Balancer(3); amount++; return(Instance3); } else { amount++; int num = amount % 3; switch (num) { case 1: uniqueInstance = Instance1; break; case 2: uniqueInstance = Instance2; break; case 0: uniqueInstance = Instance3; break; } } return(uniqueInstance); }