暂无描述

aleukhin c9340c12b3 1st com 7 月之前
ConsoleApp1 c9340c12b3 1st com 7 月之前
.gitignore.txt c9340c12b3 1st com 7 月之前
readme.md c9340c12b3 1st com 7 月之前

readme.md

oсновы LINQ

string[] teams = {"колодки", "шатуны", "фильтр", "банка", "подсос"};

var selectedTeams = new List<string>();

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);
 вывод: 

фильтр

Process finished with exit code 0.

### 4

using System; List users = new List {

new User {
    Name="Миша", 
    Age=42, 
    Languages = new List<string> {
        "английский", "немецкий" }},
new User {
    Name="Михаил", 
    Age=17, 
    Languages = new List<string> {
        "английский", "французский" }},
new User {
    Name="Валерий", 
    Age=39, 
    Languages = new List<string> {
        "английский", "испанский" }},

};

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<string> Languages { get; set; }

}

вывод:

Миша - 42 Валерий - 39

### 5

List users = new List() {

new User { Name = "Петя", Age = 33 },
new User { Name = "Ваня", Age = 21 },
new User { Name = "Вася", Age = 43 }

};

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; }

}

вывод:

Ваня - 21 Вася - 43 Петя - 33 ```