public static void Main(string[] args) { string[] peopleArgs = Console.ReadLine().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); string[] productsArgs = Console.ReadLine().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); HashSet <Person> people = new HashSet <Person>(); HashSet <Product> products = new HashSet <Product>(); AddAllPeople(peopleArgs, people); AddAllProducts(productsArgs, products); string command = Console.ReadLine(); while (command.ToLower() != "end") { string[] commandArgs = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); string personName = commandArgs[0]; string productName = commandArgs[1]; Person currentPerson = people.Where(person => person.Name == personName).FirstOrDefault(); Product currentProduct = products.Where(prod => prod.Name == productName).FirstOrDefault(); if (currentPerson.CanAffordProduct(currentProduct.Cost)) { currentPerson.AddProduct(currentProduct); Console.WriteLine($"{personName} bought {productName}"); } else { Console.WriteLine($"{personName} can't afford {productName}"); } command = Console.ReadLine(); } foreach (Person person in people) { Console.WriteLine(person); } }