Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Movie movie1  = new Movie("Scary Movie", Genre.Comedy, 6.6);
            Movie movie2  = new Movie("American Pie", Genre.Comedy, 2.5);
            Movie movie3  = new Movie("Saw", Genre.Horror, 1.9);
            Movie movie4  = new Movie("The Shining", Genre.Horror, 4.3);
            Movie movie5  = new Movie("Rambo", Genre.Action, 3.2);
            Movie movie6  = new Movie("The Terminator", Genre.Action, 4.1);
            Movie movie7  = new Movie("Forrest Gump", Genre.Drama, 4.9);
            Movie movie8  = new Movie("12 Angru Men", Genre.Drama, 4.6);
            Movie movie9  = new Movie("Passengers", Genre.SciFi, 3.7);
            Movie movie10 = new Movie("Interstellar", Genre.SciFi, 3.3);

            List <Movie> movies = new List <Movie>()
            {
                movie1, movie2, movie3, movie4, movie5, movie6, movie7, movie8, movie9, movie10
            };

            var movies2 = (from movie in movies
                           where movie.Rating > 4
                           select movie).ToList();

            var movies3 = (from movie in movies
                           where movie.Genre == Genre.Horror || movie.Genre == Genre.SciFi
                           select movie).ToList();


            Cinema cinema1 = new Cinema("cineplex1", new List <int> {
                1, 2, 3, 4,
            }, movies);
            Cinema cinema2 = new Cinema("cineplex2", new List <int> {
                1, 2, 3, 4,
            }, movies2);
            Cinema cinema3 = new Cinema("cineplex3", new List <int> {
                1, 2, 3
            }, movies3);

            List <Cinema> cinemas = new List <Cinema>()
            {
                cinema1, cinema2, cinema3
            };

            try
            {
                Console.WriteLine("Choose cinema you want to go");

                foreach (var cinema in cinemas)
                {
                    Console.WriteLine(cinema.Name);
                }

                Console.Write("Cinema: ");
                string input = Console.ReadLine();

                if (input != "cineplex1" && input != "cineplex2" && input != "cineplex3")
                {
                    throw new Exception("You must enter valid cinema");
                }

                var cinemaYouWantToGo = (from cinema in cinemas
                                         where cinema.Name == input
                                         select cinema).FirstOrDefault();

                Console.WriteLine("Do you want  1. all movies or  2.by genre");
                string input2 = Console.ReadLine();

                if (input2 == "1")
                {
                    Console.WriteLine("Choose movie you want to watch");

                    foreach (var item in cinemaYouWantToGo.ListOfMovies)
                    {
                        Console.WriteLine($"{item.Title} - {item.Genre} / {item.TicketPrice}");
                    }
                }
                else if (input2 == "2")
                {
                    Console.WriteLine("Enter your favorite genre");

                    foreach (var item in cinemaYouWantToGo.ListOfMovies)
                    {
                        Console.WriteLine(item.Genre);
                    }

                    Console.WriteLine();
                    Console.Write("Genre: ");
                    string inputGenre = Console.ReadLine().ToLower();

                    Genre favoriteGenre = new Genre();

                    switch (inputGenre)
                    {
                    case "action":
                        favoriteGenre = Genre.Action;
                        break;

                    case "horror":
                        favoriteGenre = Genre.Horror;
                        break;

                    case "comedy":
                        favoriteGenre = Genre.Comedy;
                        break;

                    case "drama":
                        favoriteGenre = Genre.Drama;
                        break;

                    case "scifi":
                        favoriteGenre = Genre.SciFi;
                        break;

                    default:
                        throw new Exception("You enter wrong genre");
                    }

                    Console.WriteLine("Choose movie you want to watch");
                    var moviesByGenre = (from movie in cinemaYouWantToGo.ListOfMovies
                                         where movie.Genre == favoriteGenre
                                         select movie).ToList();

                    foreach (var item in moviesByGenre)
                    {
                        Console.WriteLine($"{item.Title} - {item.Genre} / {item.TicketPrice} $");
                    }
                }
                else
                {
                    throw new Exception("You must enter 1 or 2");
                }

                Console.WriteLine();
                Console.Write("Movie: ");
                string movieToWatch = Console.ReadLine().ToLower();

                var watchingMovie = (from movie in cinemaYouWantToGo.ListOfMovies
                                     where movie.Title.ToLower() == movieToWatch
                                     select movie).FirstOrDefault();

                cinemaYouWantToGo.MoviePlaying(watchingMovie);
            }

            catch (NullReferenceException)
            {
                Console.WriteLine("You entered wrong movie");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            //LINQ немедленое выполнение
            //string[] names = { "Sasha+Inna", "Sasha+Oksana", "Igor", "mISHA", "Sasha+Naruto", "Beer" };
            //LINQ linq = new LINQ();
            //string[] result = linq.TestLinq(names);
            //foreach(var i in result)
            //{ Console.WriteLine(i); }
            ////LINQ отложеное выполнение, вместо var  почти всегда подходит IEnumerable<T>
            //var sasha = from i in names where i.Contains("Sasha") select i;
            //foreach(var k in sasha)
            //{ Console.WriteLine(k); }

            Cinema cinema = new Cinema();

            cinema.ShowViewers();
            cinema.agregate();

            //простой делегат

            //Glava10.Binary b = new Glava10.Binary(Glava10.SimpleMath.Add);
            //Console.WriteLine(b(10, 5));
            //Glava10.DelegateInfo(b);

            //применения делегатов для обратных вызовов в приложениях,

            //Glava10.Car c1 = new Glava10.Car(10, 100, "dog");
            //c1.RegisterWithCarEngine(new Glava10.Car.CarEngineHandler(OnCarEngineEvent));
            //c1.RegisterWithCarEngine(new Glava10.Car.CarEngineHandler(OnCarEngineEvent1));


            //Console.WriteLine("***** Speeding up *****");
            //for (int i = 0; i < 6; i++)
            //    c1.Accelerate(20);

            //Что бы не писать ((c1.RegisterWithCarEngine(new Glava10.Car.CarEngineHandler(OnCarEngineEvent));))
            // можно указать просто метод, например:

            //Glava10.Car c2 = new Glava10.Car(10, 100, "Cat");
            //c2.RegisterWithCarEngine(DelegtText);
            //Console.WriteLine("***** Speeding up *****");
            //for (int i = 0; i < 6; i++)
            //    c2.Accelerate(20);

            //Использование специальных обобщенных делегатов Action i Func

            //Action<string, ConsoleColor, int> actionTarget = new Action<string, ConsoleColor, int>(Glava10.DisplayMessage);
            //actionTarget("sasha", ConsoleColor.Red, 5);

            //Func<int, int, int> funcTarget = new Func<int, int, int>(Glava10.Metod_func);//полная запись
            //Console.WriteLine(funcTarget(10,50));
            //Func<int, int, int> func1 = Glava10.SimpleMath.Add;//можно просто указать имя метода
            //Console.WriteLine(func1(99, 99));

            //События

            //Glava10.Car2 car2 = new Glava10.Car2(10, 100, "bob");
            //car2.Exploed += OnCarEngineEvent;
            //car2.AboutToBlow += OnCarEngineEvent1;
            //Glava10.Car2.CarEngineYandler d = new Glava10.Car2.CarEngineYandler(DeledFunk);
            //car2.AboutToBlow += d;
            //car2.AboutToBlow += delegate (string s)//использование анонимных методов вместо фунций
            //{
            //    Console.WriteLine("Using anonim method {0}", s);
            //    car2.PetName2 = "Ssss";
            //};
            //car2.AboutToBlow += (string ss) => { Console.WriteLine("Using Lambda: {0}", ss); };// использование лямда выражений

            //for (int i = 0; i < 6; i++)
            //    car2.Accelerate2(20);
            //car2.AboutToBlow -= d;
            //Console.WriteLine(car2.PetName2);

            //использование лямбда выражений

            //List<int> list = new List<int>();
            //list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            //List<int> eventNumbers = list.FindAll(delegate (int i)
            //     { return (i % 2) == 0; }) ;
            //List<int> NeChetni = list.FindAll(i => (i % 2) != 0);//использование сокращенной записи
            //foreach (int e in eventNumbers)
            //    Console.WriteLine(e);
            //foreach (int x in NeChetni)
            //    Console.WriteLine(x);

            ////ИНТЕРФЕЙСЫ
            //Shape[] s = { new Triangle("Triangle", 3), new Square("square"), new Circle("circle", 34) };
            //for(int i =0; i < s.Length; i++)
            //{
            //    if (s[i] is IPoint ip)
            //    {
            //        Console.WriteLine("The {0}  have {1} points", s[i].Name, ip.Points);
            //    }
            //    else Console.WriteLine("The {0} dont have points", s[i].Name);
            //}

            //Number num = new Number();
            //foreach(One t in num)
            //{
            //    Console.WriteLine(t.O);
            //}
            ////use yield
            //Second ss = new Second();
            //foreach (Two tt in ss)
            //    Console.WriteLine(tt.T);

            // ИСКЛЮЧЕНИЯ
            //FunWithExeption test = new FunWithExeption("Sasha", 20);
            //try
            //{
            //    test.BuyBeer();
            //}
            //catch(Exception t)
            //{
            //    Console.WriteLine(t.Message);
            //    Console.WriteLine(t.Source);
            //    Console.WriteLine(t.HelpLink);
            //}


            //Наследование, полиморфизм
            //Mersedes mers = new Mersedes(120,100,5,"AMG",12.3);
            //mers.Display();
            //mers.Transmishion("avto");

            //свойства properties
            //Prop prop = new Prop();
            //prop.PetName = "Mazda";
            //prop.MyCar.Id = 1444444;
            //Console.WriteLine("{0}----{1}", prop.Speed,prop.MyCar.Pay );
            //prop.MyCar.Print();
            //Employee e = new Employee("Sasha", 124, 10000);
            //e.GiveBonus(999);
            //e.Print();
            //e.Name = "Inna";

            //Car bibi = new Car();
            //bibi.PrintInfoCar();
            //Car bib = new Car("Toyota",99);
            //bib.PrintInfoCar();

            //Part_Two.Arrays();

            //double[] kk = {1.2, 1.4, 0.4 };
            //Console.WriteLine(Part_Two.Avg(kk));

            //Console.WriteLine(ReloadOperators.Add(3, 5));
            //Console.WriteLine(ReloadOperators.Add("Sasha","Grinchuck" ));

            //DataType.LearnENum();
            //UseStructures.UsePoint();
            //FunTuple.Tup();

            //Создание екземпляра класса и вызов его метода
            //Part_Two Test = new Part_Two();
            //Console.WriteLine(Test.Avg(kk));
            // Перший спосіб написання циклу используеться при когда нужно конкретное к-во повторений
            //for (int i = 0; i < args.Length; i++)
            //    Console.WriteLine("Arg : {0}", args[i]);

            // другрий спосіб написання циклу используется для итерации по контейнеру

            //foreach (string arg in args)
            //  Console.WriteLine("Argument: {0}", arg);



            //UsingForeach(args);
            //UseReadline();
            //LocalVar();
            //NewAndDefault();
            //UseChar();
            //UseParse();
            //ParseFromStringsWithTryParse();
            //UseBigInteger();
            //StringFunctionality();
            //UseStringBilder();
            //TypesConvertation();
            //NeYavnoType();
            //Cikle_and_IF();
            //SwitchOnStnngExample();
            Console.ReadLine();

            return(-1);
        }