Example #1
0
        public void PrintAllProducts(decimal maxPrice)
        {
            if (maxPrice >= 0)
            {
                var phonesAndAccessoriesBelowGivenMaxPrice = Phones.Concat(Accessories).Where(x => x.Value <= maxPrice).ToList();
                if (phonesAndAccessoriesBelowGivenMaxPrice.Count == 0)
                {
                    Console.WriteLine("Not found");
                }
                else
                {
                    int check = 0;
                    foreach (var item in phonesAndAccessoriesBelowGivenMaxPrice.OrderBy(x => x.Key).ToList())
                    {
                        check++;

                        if (check == 2)
                        {
                            Console.Write("{0},\n", item.Key);
                            check = 0;
                        }
                        else
                        {
                            Console.Write("{0}, ", item.Key);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine(message);
            }
        }