pluralsight-linq-fundamentals/Queries/Program.cs

34 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Queries
{
class Program
{
static void Main(string[] args)
{
var movies = new List<Movie>
{
new Movie {Title = "The Dark Knight", Rating = 8.9f, Year = 2008},
new Movie {Title = "The King's Speech", Rating = 8.0f, Year = 2010},
new Movie {Title = "Casablanca", Rating = 8.5f, Year = 1942},
new Movie {Title = "Star Wars V", Rating = 8.5f, Year = 1980}
};
// filter operator from LINQ
var query = movies.Where(m => m.Year > 2000);
foreach (var movie in query)
{
Console.WriteLine(movie.Title);
}
// filter operator using customized Filter extension
var query2 = movies.Filter(m => m.Year > 2000);
foreach (var movie in query2)
{
Console.WriteLine(movie.Title);
}
}
}
}