Ejemplo n.º 1
0
        private static void UseExpressions()
        {
            Action printanEmptyLine = () => Console.WriteLine("Hello");

            printanEmptyLine();

            Expression <Action <int> > PrintAnInteger = x => Console.WriteLine(x);

            Action <int, int> PrintTwoIntegers = (x, y) => Console.WriteLine($"{x} and \n {y}");



            Action <int> Print = PrintAnInteger.Compile();

            Print(2);

            PrintTwoIntegers(5, 6);

            Func <DateTime> dateTime = () => DateTime.Now;

            Console.WriteLine(dateTime());

            Func <int, int> square = (t) => t * t;

            Func <int, int, int> multiply = (x, y) => x * y;

            Console.WriteLine(multiply(10, 15));
            Console.WriteLine(square(15));

            MovieReviewsDataContext mrdc   = new MovieReviewsDataContext();
            IEnumerable <Movie>     movies = mrdc.Movies;
        }
Ejemplo n.º 2
0
        static void QuerySql()
        {
            MovieReviewsDataContext context = new MovieReviewsDataContext();

            IEnumerable <Movie> movies = from dc in context.Movies
                                         where dc.ReleaseDate.Year >= 2008
                                         orderby dc.Reviews.Average(x => x.Rating) descending
                                         select dc;

            foreach (Movie m in movies)
            {
                Console.WriteLine(m.Title);
            }
        }