### основы LINQ ``` string[] teams = {"бампер", "катки", "тонер", "лобаш", "мафон"}; var selectedTeams = new List(); foreach(string s in teams) { if (s.ToUpper().StartsWith("Б")) selectedTeams.Add(s); } selectedTeams.Sort(); foreach (string s in selectedTeams) Console.WriteLine(s); ``` ## Вывод ``` бампер ``` ### 2 ``` string[] teams = {"бампер", "катки", "тонер", "лобаш", "мафон"}; var selectedTeams = from t in teams where t.ToUpper().StartsWith("к") orderby t select t; foreach (string s in selectedTeams) Console.WriteLine(s); ``` ## Вывод ``` катки ``` ### 3 ``` string[] teams = {"бампер", "катки", "тонер", "лобаш", "мафон", "вонючка"}; var selectedTeams = teams .Where(t=>t.ToUpper().StartsWith("т")) .OrderBy(t => t); foreach (string s in selectedTeams) Console.WriteLine(s); ``` ## Вывод ``` тонер ``` ### 4 ``` using System; List users = new List { new User { Name="Толян", Age=19, Languages = new List { "английский", "немецкий" }}, new User { Name="Максон", Age=23, Languages = new List { "английский", "французский" }}, new User { Name="Юрас", Age=32, Languages = new List { "английский", "испанский" }}, new User { Name="Лехыч", Age=54, Languages = new List { "испанский", "немецкий" }} }; var selectedUsers = users.Where(u => u.Age > 25); foreach (User user in selectedUsers) Console.WriteLine($"{user.Name} - {user.Age}"); public class User { public string Name { get; set; } public int Age { get; set; } public List Languages { get; set; } } ``` ## Вывод ``` Юрас - 32 Лехыч - 54 ``` ### 5 ``` List users = new List() { new User { Name = "Толян", Age = 19 }, new User { Name = "Максон", Age = 23 }, new User { Name = "Юрас", Age = 32 }, new User { Name = "Лехыч", Age = 54 } }; var result = users .OrderBy(u => u.Name) .ThenBy(u => u.Age); foreach (User u in result) Console.WriteLine($"{u.Name} - {u.Age}"); public class User { public string Name { get; set; } public int Age { get; set; } } ``` ## Вывод ``` Лехыч - 54 Максон - 23 Толян - 19 Юрас - 32 ``` #### THE END...