using System using System Collections Generic using System Linq using

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class student
{
public string first { get; set; }
public string last { get; set; }
public int id { get; set; }
public int[] scores;
public override string ToString()
{
return first + ' ' + last + ' '+ id;
}
}
class Program
{
static void Main(string[] args)
{
student[] stud = new student[4] { new student { first = "Garaev", last = "raf", id = 111, scores = new int[] { 5, 5, 5, 4 } },
new student { first = "ivanov", last = "ivan", id = 112, scores = new int[] { 4, 5, 3, 4 } },
new student { first = "igor", last = "igor", id = 113, scores = new int[] { 4, 5, 3, 5 } },
new student { first = "vanya", last = "vanya", id = 114, scores = new int[] { 4, 2, 3, 4 } }, };
foreach (student s in stud)
{
Console.WriteLine(s);
}
// student r = new student;
Console.WriteLine();
Console.WriteLine("Первый запрос");
IEnumerable<student> Query1 =
from r in stud
where r.id > 111
select r;
Console.WriteLine();
foreach (student s in Query1)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("Второй запрос");
IEnumerable<string> Query2 =
from r in stud
where r.id > 111
select r.last;
Console.WriteLine();
foreach (string s in Query2)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("Третий запрос");
IEnumerable<int> Query3 =
from r in stud
where r.id > 111
select r.scores[0];
Console.WriteLine();
foreach (int s in Query3)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("Четвёртый запрос");
IEnumerable<double> Query4 =
from r in stud
where r.id > 111
select r.scores.Average();
Console.WriteLine();
foreach (double s in Query4)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("Пятый запрос");
var Query5 =
from r in stud
where r.id > 111
select new { r.first, r.last };
Console.WriteLine();
foreach (var s in Query5)
{
Console.WriteLine(s.first + ' ' + s.last);
}
//в мсдн изменить переделать запросы ПРИМЕР
Console.WriteLine();
Console.WriteLine("Шестой запрос");
IEnumerable<student> num1 = stud.Where(r => r.id > 111);
foreach (student s in num1)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("седьмой запрос");
IEnumerable<string> num2 = stud.Where(r => r.id > 111).Select(r => r.last);
foreach (string s in num2)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("Восьмой запрос");
IEnumerable<int> num3 = stud.Where(r => r.id > 111).Select(r => r.scores[0]);
foreach (int s in num3)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("Девятый запрос");
IEnumerable<double> num4 = stud.Where(r => r.id > 111).Select(r =>r.scores.Average());
foreach (double s in num4)
{
Console.WriteLine(s);
}
Console.WriteLine();
Console.WriteLine("десятый запрос");
var num5 = stud.Where(r => r.id > 111).Select(r => new { r.first, r.last });
foreach (var s in num5)
{
Console.WriteLine(s.first + ' ' + s.last);
}
Console.WriteLine("Работает!!");
}
}
}