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); } }