Csharp/CSharp Tutorial/LINQ/FindAll
Версия от 15:31, 26 мая 2010; (обсуждение)
Data Filtering And Sorting
using System;
using System.Collections.Generic;
using System.ruponentModel;
class Film
{
public string Name { get; set; }
public int Year { get; set; }
public override string ToString()
{
return string.Format("Name={0}, Year={1}", Name, Year);
}
}
class MainClass
{
static void Main()
{
var films = new List<Film>
{
new Film {Name="J", Year=1975},
new Film {Name="H", Year=2000},
new Film {Name="T", Year=1995}
};
Action<Film> print = film => Console.WriteLine(film);
Console.WriteLine("All films");
films.ForEach(print);
Console.WriteLine();
Console.WriteLine("Oldies");
films.FindAll(film => film.Year < 1980).ForEach(print);
Console.WriteLine();
Console.WriteLine("Sorted");
films.Sort((f1, f2) => f1.Name.rupareTo(f2.Name));
films.ForEach(print);
}
}