static void Main(string[] args) { try { Console.WriteLine("---------------------Создаем объекты, выводим инфу---------------------\n"); Table stol = new Table(300, true, "сосны"); stol.Info(); Printer testException = new Printer(500, true, 19, false); Printer firstPrinter = new Printer(400, true, 70, false); firstPrinter.Info(); Printer secondPrinter = new Printer(369, false, 55, false); secondPrinter.Info(); HeadPhones firstHeadPhones = new HeadPhones(30, true, false, "Panasonic", false); firstHeadPhones.Info(); Console.WriteLine("\n-----------Использовали перечисление-----------"); firstHeadPhones.ProductCondition = (int)Condition.best; Console.WriteLine("Состояние наушников - {0} из 5 ", firstHeadPhones.ProductCondition); HeadPhones secondHeadPhones = new HeadPhones(200, false, true, "Apple", true); Console.WriteLine("\n-----------Дальше инфа об объектах-----------"); secondHeadPhones.Info(); Computer firstComputer = new Computer(1900, true, "Intel Core i5", "DDR4", false); firstComputer.Info(); Computer secondComputer = new Computer(1000, false, "AMD", "DDR2", true); secondComputer.Info(); Console.WriteLine("------------Проверяем ПК на портативность(метод интерфейса)------------\n"); Console.WriteLine("1ый: "); firstComputer.Portable(); Console.WriteLine(); Console.WriteLine("2ой: "); secondComputer.Portable(); Console.WriteLine(); Console.WriteLine("\n-----------Дальше инфа об объектах-----------"); Monitor firstMonitor = new Monitor(250, true, 600, false); firstMonitor.Info(); Monitor secondMonitor = new Monitor(1000, false, 2800, true); secondMonitor.Info(); Product firstProjector = new Projector(1231, false, "Belarus"); Product secondProjector = new Projector(609, true, "Russia"); Console.WriteLine("Стоимость проектора - {0} рубль(ей)", firstProjector.Price); //доступна только стоимость, //т.к. ссылке на объект базового класса присвоен объект производного класс Console.WriteLine("Есть ли 1ый в наличии? -" + firstProjector.InStock); Console.WriteLine("\n----------Реализуем одноименный метод из интерфейса и класса----------"); Console.Write(firstPrinter.SomeMethod()); //одноименный метод, вызывается реализованный с помощью абстрактного класса Console.WriteLine(((IPortable)firstPrinter).SomeMethod()); //.., реализованный с помощью интерфейса Console.WriteLine("\n-------Вызываем переопределенные методы-------"); Console.WriteLine("ToString() - " + firstProjector.ToString()); Console.WriteLine("GetHashCode() - " + firstProjector.GetHashCode()); Console.WriteLine("Equals() - " + firstProjector.Equals(secondProjector) + "\n"); Console.WriteLine("\n----------Операторы IS, AS ----------"); //is Boolean check = firstPrinter is IPortable; Boolean check2 = firstProjector is IPortable; Console.WriteLine(check); Console.WriteLine(check2 + "\n"); //as Printer p = new Printer(200, true, 20, true); Technique b = p as Technique; if (b != null) //проверка на успешное преобразование { b.Info(); Console.WriteLine(); } Console.WriteLine("----------Просто работка с массивом объектов----------"); Product[] ArrayOfObjects = { firstPrinter, firstMonitor, firstComputer }; //массив ссылок на разнотипные объекты foreach (Product x in ArrayOfObjects) { Console.WriteLine(TaskPrinter.IAmPrinting(x)); //вызываем метод IAmPrinting со всеми ссылками в качестве аргументов } Console.WriteLine("\n----------Использовали структуру----------"); Printer printer = new Printer(400, true, 100, false); var a = printer.spec; a.height = 450; a.width = 300; Console.WriteLine("Принтер имеет размеры: " + a.width + "х" + a.height + "\n"); Monitor monik = new Monitor(200, false, 600, true); monik.spec.height = 1080; monik.spec.width = 1920; Console.WriteLine("Монитор имеет разрешение: " + monik.spec.width + "х" + monik.spec.height + "\n"); //Реализуем класс-контейнер: добавляем объекты в массив Cabinet cabinet = new Cabinet(); cabinet.Add(stol); //1 cabinet.Add(firstPrinter); //2 cabinet.Add(firstMonitor); //3 cabinet.Add(firstHeadPhones); //4 cabinet.Add(firstComputer); //5 cabinet.Add(firstProjector); //6 cabinet.Add(secondMonitor); //7 cabinet.Add(secondComputer); //8 cabinet.Add(secondPrinter); //9 string mySurname = "Ника"; Debug.Assert(mySurname == "Ника", "Я не алмдаьыаьэм, а Ника."); CabinetMethods cabinetMethods = new CabinetMethods(); Console.WriteLine("----------Выводим объекты в порядке убывания их стоимости----------"); cabinetMethods.WritePriceDes(cabinet); Console.WriteLine("\n--------------------"); cabinetMethods.AllCount(cabinet); Console.WriteLine("\n----------Какое оборудование устарело?----------"); cabinetMethods.OldProduct(cabinet); int proverka1 = 5; Console.WriteLine("Введите число: "); int proverka2 = int.Parse(Console.ReadLine()); int proverka = proverka1 / proverka2; int[] array = { 1, 2, 3 }; int i = int.Parse(Console.ReadLine()); if (i > array.Length) { throw new OutOfIndexException("Выход индекса за границы"); } Console.WriteLine(array[i]); Console.WriteLine("Выполнено без ошибок"); } catch (PriceException ex) { Console.WriteLine("ОШИБКА: " + ex.Message); } catch (NullException ex) { Console.WriteLine("ОШИБКА: " + ex.Message); } catch (OutOfIndexException ex) { Console.WriteLine("ОШИБКА: " + ex.Message); } catch (Exception ex) { Red(); Console.WriteLine("\t\t ОШИБКА"); Console.WriteLine(ex.Message + "\n\n"); Console.WriteLine(ex.TargetSite + "\n\n"); //имя метода, в котором произошла ошибки Console.WriteLine(ex.StackTrace + "\n\n"); } finally { Console.WriteLine("\nВызвался finally"); } }