static void Main(string[] args) { Test test1 = new Test("mathematic", 10); Exams exam1 = new Exams("biolagy", 15); FinalExam final_exam1 = new FinalExam("fisiks", 11, 6); final_exam1.Clone(); ((Ialive)final_exam1).Clone(); Exams exam2 = new Exams("chemistry", 20); FinalExam final_exam2 = exam2 as FinalExam; if (final_exam2 == null) { Console.WriteLine("No corret conversion"); } FinalExam final_exan3 = new FinalExam("logistic", 12, 4); Exams exam3 = final_exan3 as Exams; if (exam3 == null) { Console.WriteLine("No corret conversion"); } else { Console.WriteLine("Corret conversion"); } Console.WriteLine("test1 is Test " + (test1 is Test)); Console.WriteLine("test1 is Exam " + (test1 is Exams)); Console.WriteLine("exam1 is Test " + (exam1 is Test)); Console.WriteLine("exam1 is Exam " + (exam1 is Exams)); Console.WriteLine(exam2.ToString()); Printer printer = new Printer(); printer.IAmPrinting(final_exan3); Console.WriteLine("----------------------Array-----------------------"); Question[] questions = new Question[] { test1, exam1, final_exam1 }; for (int i = 0; i < questions.Length; i++) { printer.IAmPrinting(questions[i]); Console.WriteLine("--------------------------------------"); } }
static void Main(string[] args) { Car c1 = new Car("Audi", "black", 120, "J-500-1"); Car c2 = new Car("WalkSwagen", "blue", 120, "e-500-1"); Car c3 = new Car("Sitroen", "green", 130, "rw-500-1"); Car c4 = new Car("Audi", "black", 120, "J-500-1"); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); c1.GetInfo(); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); ((IEngine)c1).GetInfo(); Console.WriteLine(c1.Equals(c4)); Console.WriteLine(c1.Equals(c2)); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); c3.GetInfo(); IEngine n = c3 as IEngine; if (n != null) { n.GetInfo(); } Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); Train t1 = new Train("BelTrain", "blue", 100, true, 8); Train t2 = new Train("BelTrain", "green", 100, true, 8); Train t3 = new Train("BelTrain", "white", 70, false, 8); Train t4 = new Train("BelTrain", "blue", 120, false, 8); Train t5 = new Train("BelTrain", "orange", 100, true, 8); Transport tt1 = t1 as Transport; Transport tt2 = c1 as Transport; Console.WriteLine(tt1 is IEngine); Train t6 = tt2 as Train; if (t6 != null) { Console.WriteLine("Первую машину удалось привести к типу Train"); } else { Console.WriteLine("Преобразование не удалось"); } Printer p1 = new Printer(); Transport tt5 = new Car("Opel", "white", 111, "J-213-1"); Transport[] mass = { c1, c2, c3, t1, tt1, tt2, tt5 }; foreach (Transport t in mass) { Console.WriteLine(); p1.IAmPrinting(t); } }
static void Main(string[] args) { Producer Olya = new Producer(); Producer Kail = new Producer(); Person person = new Person(); Person persona = Kail; Producer Olu = (Producer)person; if (person is Producer) { Producer Igor = (Producer)person; } else { Console.WriteLine("Преобразовать нельзя"); } Producer Lip = person as Producer; if (Lip == null) { Console.WriteLine("Преобразование прошло неудачно"); } else { Console.WriteLine("Преобразование удалось"); } Kail.name = "Kail"; Kail.Move(); Console.WriteLine(Kail.ToString()); Console.WriteLine(persona.name); Film Transformers = new Film(15); Cartoon Naruto = new Cartoon(6); News GC = new News(21); Printer Print = new Printer(); Transformers.Watch(); Naruto.Watch(); GC.Watch(); List <object> array = new List <object>() { Kail, person, Naruto, GC, Transformers, Print }; foreach (object ch in array) { Print.IAmPrinting(ch); } }
public void Search(List <Transport> pozhar) { int speed; Console.WriteLine("Input the speed"); speed = Convert.ToInt32(Console.ReadLine()); int schetchik = 0; foreach (Transport pp in pozhar) { if (pp.Speed == speed) { Console.WriteLine("Найдено совпадение"); Printer printer = new Printer(); printer.IAmPrinting(pp); schetchik++; } } if (schetchik == 0) { Console.WriteLine("Совпадений не найдено!"); } return; }
static void Main(string[] args) { Producer Kail = new Producer(); Person person = new Person(); Person persona = Kail; if (person is Producer) { Producer Igor = (Producer)person; } else { Console.WriteLine("Преобразовать нельзя"); } Producer Lip = person as Producer; if (Lip == null) { Console.WriteLine("Преобразование прошло неудачно"); } else { Console.WriteLine("Преобразование удалось"); } Kail.name = "Kail"; Kail.Move(); Console.WriteLine(Kail.ToString()); Console.WriteLine(persona.name); Film Transformers = new Film(2005); Film Hello = new Film(2003); Transformers.time = 245; Cartoon Naruto = new Cartoon(6); News GC = new News(21); News LL = new News(18); Printer Print = new Printer(); Transformers.Watch(); Naruto.Watch(); GC.Watch(); ProgramGuide Hai = new ProgramGuide(); Hai.Year = 2015; ProgramGuide Hai2 = new ProgramGuide(); Hai.Year = 2003; ProgramGuide Hai3 = new ProgramGuide(); Hai.Year = 2015; ProgramGuide Hai4 = new ProgramGuide(200); Hai.Year = 2007; List <object> array = new List <object>() { Kail, person, Naruto, GC, Transformers, Print }; foreach (object ch in array) { Print.IAmPrinting(ch); } List <ProgramGuide> film = new List <ProgramGuide>() { Hai, Hai2, Hai3 }; film.Add(Hai4); Controller.Count(); Controller.Search(film); Hai4.Inf(); }
static void Main(string[] args) { Producer Kail = new Producer(); Person person = new Person(); Person persona = Kail; if (person is Producer) { Producer Igor = (Producer)person; } else { Console.WriteLine("Преобразовать нельзя"); } Producer Lip = person as Producer; if (Lip == null) { Console.WriteLine("Преобразование прошло неудачно"); } else { Console.WriteLine("Преобразование удалось"); } Kail.name = "Kail"; Kail.Move(); Console.WriteLine(Kail.ToString()); Console.WriteLine(persona.name); Film Transformers = new Film(2005); Film Hello = new Film(2003); Transformers.time = 245; Cartoon Naruto = new Cartoon(6); News GC = new News(21); News LL = new News(18); Printer Print = new Printer(); Transformers.Watch(); Naruto.Watch(); GC.Watch(); ProgramGuide Hai = new ProgramGuide(); Hai.Year = 2015; ProgramGuide Hai2 = new ProgramGuide(); Hai.Year = 2003; ProgramGuide Hai3 = new ProgramGuide(); Hai.Year = 2015; ProgramGuide Hai4 = new ProgramGuide(200); Hai.Year = 2007; List <object> array = new List <object>() { Kail, person, Naruto, GC, Transformers, Print }; foreach (object ch in array) { Print.IAmPrinting(ch); } List <ProgramGuide> film = new List <ProgramGuide>() { Hai, Hai2, Hai3 }; film.Add(Hai4); Controller.Count(); Controller.Search(film); Hai4.Inf(); // 7 Laba try { User Andrey = new User("Andrey", 19); Film Hello1 = new Film(2003); Film Hello2 = new Film(-200); // error1 int a = 0; int b = 100 / a; // eror2 string[] kre = new string[5]; kre[5] = "dfr"; // error3 News QWE = new News(2888); // error4 User Igor = new User("", -30); Igor.Info(); // error5 int?pointer = null; Assert(pointer != null, "переменная равна -- null"); } catch (NullStringException e) { Console.WriteLine(e); } catch (IndexOutOfRangeException e) { Console.WriteLine(e); } catch (YearException e) { Console.WriteLine(e); } catch (AgeLimitException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e); } finally { Console.WriteLine("Проверка завершена!"); } }