static void Main(string[] args) { Dig dig = Dig.ONE; Console.WriteLine(dig); dig++; Console.WriteLine(dig); SomeStruct someStruct = new SomeStruct("Ilya", 18); someStruct.DisplayNameAndAge(); string name = someStruct.name; Port port = new Port(3); port[0] = new Boat(44, "Ilya", 18); port[1] = new Sailboat(777, "Ilya", 28); port[2] = new Corvette(7878787, "Petr Poroshenko", 999, 3232); port[5] = new Boat(444, "qd", 4); foreach (Ship ship in PortController.AllCaptainsAgeLessThan35(port)) { ship.GetVehicleInf(); } Console.WriteLine("Displacement of all sailboats: " + PortController.CalculateDisplacement(port)); Console.WriteLine("Seats of all steamers: " + PortController.SteamerSeats(port)); }
static void Main(string[] args) { Ship boat = new Boat(500, "Ilya", "boat"); Ship corvette = new Corvette(double.MaxValue, "Petr Poroshenko", "Corvette", 666); Ship sailboat = new Sailboat(10000, "Aleksey Navalny", "Sailboat"); Ship steamer = new Steamer(double.MaxValue / 100, "Vitya Neptun", "Steamer"); Console.WriteLine("==============================================="); Console.WriteLine("==============================================="); boat.Move(); boat.GetVehicleInf(); Console.WriteLine("==============================================="); corvette.Move(); corvette.GetVehicleInf(); Console.WriteLine("==============================================="); sailboat.Move(); sailboat.GetVehicleInf(); Console.WriteLine("==============================================="); steamer.Move(); steamer.GetVehicleInf(); Console.WriteLine("==============================================="); Ship secondBoat = new Boat(200, "Privet Andrey", "boat"); Console.WriteLine($"Equals?\t{boat.Equals(secondBoat)}"); Console.WriteLine($"Type?\t{boat.ToString()}"); Console.WriteLine($"My own hash: {boat.GetHashCode()}"); Console.WriteLine("==============================================="); Console.WriteLine("One-name methods: "); IVehicle icorvette = new Corvette(90000, "Borodina Elizaveta", "Corvette", 222); icorvette.OneNameMethod(); ICaptain isteamer = new Steamer(5677, "Pushkin Aleksandr", "steamer"); isteamer.OneNameMethod(); Console.WriteLine("==============================================="); Console.WriteLine(icorvette.GetType()); if (icorvette is IVehicle) { Console.WriteLine("Its have a IVehicle type"); } else { Console.WriteLine("Wrong"); } if (icorvette is ICaptain) { Console.WriteLine("Its have a ICaptain type"); } else { Console.WriteLine("Wrong"); } if (icorvette is Corvette) { Console.WriteLine("Its have a Corvette type"); } else { Console.WriteLine("Wrong"); } Object someObj = corvette; icorvette = someObj as Corvette; if (icorvette != null) { Console.WriteLine("Good"); } else { Console.WriteLine("Bad"); } Console.WriteLine("==============================================="); object[] ListOfObjescts = new object[] { boat, corvette, sailboat, steamer }; foreach (ICaptain cap in ListOfObjescts) { Printer.iAmPrinting(cap); } }
static void Main(string[] args) { Port port = new Port(4); try { port[0] = new Boat(44, "Ilya", 18, 0.45F); port[1] = new Sailboat(777, "Ilya", 28, 0.65F); //port[0] = new Boat(0, "Vitya", 20, 0.1); //port[1] = new Boat(11, "Vanya", 11, 1.1); //Console.WriteLine(port[5]); port[5] = new Boat(444, "Ilya", 4, 0.30F); } catch (PortException exception) { Console.WriteLine($"Error: {exception.Message} in {exception.ErrorClass}, actual: {exception.CountException}, expected: {exception.ExpectedCount}"); } catch (VehicleException exception) { Console.WriteLine($"Error: {exception.Message} - {exception.CarringException}"); } finally { Console.WriteLine("Finally block"); } Console.WriteLine(); try { port[0] = new Boat(44, "Ilya", 18, 0.45F); //port[1] = new Sailboat(777, "Ilya", 28, 0.65F); port[1] = new Boat(-99, "Valya", 99, 0.4); //Console.WriteLine(port[5]); port[5] = new Boat(444, "Ilya", 4, 0.30F); } catch (CustomException exception) { //VehicleException veh = (VehicleException)exception; //Console.WriteLine(veh.CarringException); object exc = exception as PortException; if (exc == null) { exc = exception as VehicleException; if (exc == null) { Console.WriteLine("Sorry"); } else { VehicleException vehicleException = (VehicleException)exc; Console.WriteLine($"Error: {vehicleException.Message} - {vehicleException.CarringException}"); } } else { PortException portException = (PortException)exc; Console.WriteLine($"Error: {portException.Message} in {portException.ErrorClass}, actual: {portException.CountException}, expected: {portException.ExpectedCount}"); } } Console.WriteLine(); try { Port port1 = new Port(2); port1[0] = new Boat(44, "Ilya", 18, 0.45F); port1[1] = new Boat(777, "Ilya", 28, 0.65F); //PortController.CalculateDisplacement(port1); throw new Exception("new standard exception"); } catch (Exception exception) { Console.WriteLine(exception.Message); } finally { Console.WriteLine("Hi"); } }