예제 #1
0
        public static void Main(string[] args)
        {
            logger.Info("Program started");

            string    scrubbedFile = FileScrubber.ScrubMovies("../../movies.csv");
            MovieFile movieFile    = new MovieFile(scrubbedFile);

            Console.WriteLine("Enter search criteria Below ");
            Console.WriteLine("Search by entering title of movie, album or book:");
            string response = Console.ReadLine();

            // LINQ - Where filter operator & Contains quantifier operator
            var Movies = movieFile.Movies.Where(m => m.title.Contains(response));

            // Display Movies List results after operations
            foreach (Movie m in Movies)
            {
                Console.WriteLine(m.Display());
            }
            // LINQ - Count aggregation method
            Console.WriteLine();
            Console.WriteLine($"There are {Movies.Count()} in your search");

            logger.Info("Program ended");
        }
        public static void Main(string[] args)
        {
            logger.Info("Program started");

            string    scrubbedFile = FileScrubber.ScrubMovies("../../../movies.csv");
            MovieFile movieFile    = new MovieFile(scrubbedFile);


            // LINQ - Where filter operator & Contains quantifier operator
            var Movies = movieFile.Movies.Where(m => m.title.Contains("(1990)"));

            // LINQ - Count aggregation method
            Console.WriteLine($"There are {Movies.Count()} movies from 1990");

            // LINQ - Any quantifier operator & Contains quantifier operator
            var validate = movieFile.Movies.Any(m => m.title.Contains("(1921)"));

            Console.WriteLine($"Any movies from 1921? {validate}");

            // LINQ - Where filter operator & Contains quntifier operator & Count aggregation method
            int num = movieFile.Movies.Where(m => m.title.Contains("(1921)")).Count();

            Console.WriteLine($"There are {num} movies from 1921?");

            // LINQ - Where filter operator & Contains quantifier operator
            var Movies1921 = movieFile.Movies.Where(m => m.title.Contains("(1921)"));

            foreach (Movie m in Movies1921)
            {
                Console.WriteLine(m.Display());
            }

            // LINQ - Select projection operator
            var titles = movieFile.Movies.Where(m => m.title.Contains("Shark")).Select(m => m.title);

            foreach (string t in titles)
            {
                Console.WriteLine(t);
            }

            // LINQ - OrderBy ordering operator
            var MoviesOrdered = movieFile.Movies.Where(m => m.title.Contains("Shark")).OrderBy(m => m.title);

            foreach (Movie m in MoviesOrdered)
            {
                Console.WriteLine(m.Display());
            }

            // LINQ - First element operator
            var FirstMovie = movieFile.Movies.First(m => m.title.StartsWith("Z", StringComparison.OrdinalIgnoreCase));

            Console.WriteLine($"First movie: {FirstMovie.title}");


            logger.Info("Program ended");
        }
예제 #3
0
        public static void Main(string[] args)
        {
            logger.Info("Program started");

            string    scrubbedFile = FileScrubber.ScrubMovies("../../movies.csv");
            MovieFile movieFile    = new MovieFile(scrubbedFile);

            var Movies = movieFile.Movies.Where(m => m.title.Contains("(1990)"));

            Console.WriteLine($"There are {Movies.Count()} movies from 1990.");

            var validate = movieFile.Movies.Any(m => m.title.Contains("(1921)"));

            Console.WriteLine($"Any movies from 1921?\t{validate}");

            var num = movieFile.Movies.Where(m => m.title.Contains("(1921)")).Count();

            Console.WriteLine($"There are {num} movies from 1921.");

            var movies1921 = movieFile.Movies.Where(m => m.title.Contains("(1921)"));

            foreach (Movie M in movies1921)
            {
                Console.WriteLine(M.Display());
            }

            var titles = movieFile.Movies.Where(m => m.title.Contains("Shark")).Select(m => m.title);

            foreach (string t in titles)
            {
                Console.WriteLine(t);
            }

            var MoviesOrdered = movieFile.Movies.Where(m => m.title.Contains("Shark")).OrderBy(m => m.title);

            foreach (Movie m in MoviesOrdered)
            {
                Console.WriteLine(m.Display());
            }

            var FirstMovie = movieFile.Movies.First(m => m.title.StartsWith("Z", StringComparison.OrdinalIgnoreCase));

            Console.WriteLine($"First movie: {FirstMovie.title}");

            logger.Info("Program ended");
        }