Содержание

Слайд 2

Задача

Создать метод для фильтрации массивов целых чисел, но с возможностью указания алгоритма,

Задача Создать метод для фильтрации массивов целых чисел, но с возможностью указания алгоритма, применяемого для фильтрации.
применяемого для фильтрации.

Слайд 3

Использование делегатов

public class Common
{
public delegate bool IntFilter(int i);
public static

Использование делегатов public class Common { public delegate bool IntFilter(int i); public
int[] FilterArrayOfInts(int[] ints, IntFilter filter)
{
List aList = new List();
foreach (int i in ints)
{
if (filter(i))
{
aList.Add(i);
}
}
return (aList.ToArray());
}
}

Слайд 4

Использование делегатов

class Program
{
public static bool IsOdd(int i)
{
return ((i

Использование делегатов class Program { public static bool IsOdd(int i) { return
& 1) == 1);
}
static void Main(string[] args)
{
int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] oddNums = Common.FilterArrayOfInts(nums, IsOdd);
foreach (int i in oddNums)
Console.WriteLine(i);
}
}

Слайд 5

Использование анонимных методов

int[] nums = { 1, 2, 3, 4, 5, 6,

Использование анонимных методов int[] nums = { 1, 2, 3, 4, 5,
7, 8, 9, 10 };
int[] oddNums = Common.FilterArrayOfInts(nums, delegate (int i)
{ return ((i & 1) == 1); });
foreach (int i in oddNums)
Console.WriteLine(i);

Слайд 6

Использование лямбда-выражений

(параметр1, параметр2, параметр3) => выражение
(параметр1, параметр2, параметр3) =>
{
оператор1;
оператор2;
оператор3;

Использование лямбда-выражений (параметр1, параметр2, параметр3) => выражение (параметр1, параметр2, параметр3) => {
return(тип_возврата_лямбда_выражения);
}

Слайд 7

Использование лямбда-выражений

x => x
x => x.Length>0
s => s.Length
(x,y) => x==y
(x,y) =>
{if

Использование лямбда-выражений x => x x => x.Length>0 s => s.Length (x,y)
(x>y)
return(x);
else
return(y);
}

Слайд 8

Использование лямбда-выражений

int[] nums = { 1, 2, 3, 4, 5, 6, 7,

Использование лямбда-выражений int[] nums = { 1, 2, 3, 4, 5, 6,
8, 9, 10 };
int[] oddNums = Common.FilterArrayOfInts(nums, i => ((i & 1) == 1));
foreach (int i in oddNums)
Console.WriteLine(i);

Слайд 9

LINQ (Language Integrated Query)

По большей части LINQ ориентирован на запросы — будь

LINQ (Language Integrated Query) По большей части LINQ ориентирован на запросы —
то запросы, возвращающие набор подходящих объектов, единственный объект или подмножество полей из объекта либо набора объектов.
В LINQ этот возвращенный набор называется последовательностью (sequence). Большинство последовательностей LINQ имеют тип IEnumerable, где T — тип данных объектов, находящихся в последовательности.

Слайд 10

LINQ

LINQ to Objects: применяется для работы с массивами и коллекциями
LINQ to Entities:

LINQ LINQ to Objects: применяется для работы с массивами и коллекциями LINQ
используется при обращении к базам данных через технологию Entity Framework
LINQ to Sql: технология доступа к данным в MS SQL Server
LINQ to XML: применяется при работе с файлами XML
LINQ to DataSet: применяется при работе с объектом DataSet
Parallel LINQ (PLINQ): используется для выполнения параллельных запросов

Слайд 11

LINQ (Language Integrated Query)

string[] numbers = { "40", "2012", "176", "5" };
//

LINQ (Language Integrated Query) string[] numbers = { "40", "2012", "176", "5"
Преобразуем массив строк в массив типа int используя LINQ
int[] nums = numbers.Select(s => Int32.Parse(s)).ToArray();
foreach (int n in nums)
Console.Write(n + " ");

Слайд 12

LINQ (Language Integrated Query)

string[] numbers = { "40", "2012", "176", "5" };
//

LINQ (Language Integrated Query) string[] numbers = { "40", "2012", "176", "5"
Преобразуем массив строк в массив типа int и сортируем по возрастанию используя LINQ
int[] nums = numbers.Select(s => Int32.Parse(s)).OrderBy(s => s).ToArray();

Слайд 14

Ленивые (отложенные) вычисления

Ленивые вычисления (англ. lazy evaluation, также отложенные вычисления) — применяемая в

Ленивые (отложенные) вычисления Ленивые вычисления (англ. lazy evaluation, также отложенные вычисления) —
некоторых языках программирования стратегия вычисления, согласно которой вычисления следует откладывать до тех пор, пока не понадобится их.

Слайд 15

Метод Enumerable.Range(Int32, Int32)

public static System.Collections.Generic.IEnumerable Range (int start, int count);

IEnumerable mas

Метод Enumerable.Range(Int32, Int32) public static System.Collections.Generic.IEnumerable Range (int start, int count); IEnumerable
= Enumerable.Range(2,10);
foreach (int num in mas)
Console.WriteLine(num);

var mas = Enumerable.Range(2,10);
foreach (int num in mas)
Console.WriteLine(num);

Слайд 16

Enumerable.Repeat(TResult, Int32)

public static System.Collections.Generic.IEnumerable Repeat (TResult element, int count);

IEnumerable strings =

Enumerable.Repeat (TResult, Int32) public static System.Collections.Generic.IEnumerable Repeat (TResult element, int count); IEnumerable

Enumerable.Repeat("I like programming.", 15);
foreach (String str in strings)
{
Console.WriteLine(str);
}

Слайд 17

Enumerable.Concat (IEnumerable, IEnumerable)

public static System.Collections.Generic.IEnumerable Concat (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second);

Enumerable.Concat (IEnumerable , IEnumerable ) public static System.Collections.Generic.IEnumerable Concat (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second);

Слайд 18

Enumerable.Concat (IEnumerable, IEnumerable)

var mas1 = Enumerable.Range(1,10);
var mas2 = Enumerable.Repeat(1, 10);
var mas_union = Enumerable.Concat(mas1,

Enumerable.Concat (IEnumerable , IEnumerable ) var mas1 = Enumerable.Range(1,10); var mas2 =
mas2);
var mas_union2 = mas1.Concat(mas2);

Слайд 19

Метод Enumerable.Where

public static System.Collections.Generic.IEnumerable Where (this System.Collections.Generic.IEnumerable source, Func predicate);

var mas1 =

Метод Enumerable.Where public static System.Collections.Generic.IEnumerable Where (this System.Collections.Generic.IEnumerable source, Func predicate); var
Enumerable.Range(1,10);
var mas2 = mas1.Where(x => x%2==0);

var mas1 = Enumerable.Range(1,10)
.Where(x => x%2==0);

Слайд 20

Метод Enumerable.Where

public static System.Collections.Generic.IEnumerable Where (this System.Collections.Generic.IEnumerable source, Func predicate);

int[] numbers =

Метод Enumerable.Where public static System.Collections.Generic.IEnumerable Where (this System.Collections.Generic.IEnumerable source, Func predicate); int[]
{ 0, 30, 20, 15, 90, 85, 40, 75 }; IEnumerable query = numbers.Where((number, index) => number <= index * 10);

Слайд 21

Метод Enumerable.Count

public static int Count (this System.Collections.Generic.IEnumerable source);

string[] fruits = { "apple",

Метод Enumerable.Count public static int Count (this System.Collections.Generic.IEnumerable source); string[] fruits =
"banana", "mango", "orange", "passionfruit", "grape" };
int numberOfFruits = fruits.Count();

Слайд 22

Метод Enumerable.Count

public static int Count (this System.Collections.Generic.IEnumerable source, Func predicate);

string[] fruits =

Метод Enumerable.Count public static int Count (this System.Collections.Generic.IEnumerable source, Func predicate); string[]
{ "apple", "banana", "mango", "orange", "passionfruit", "grape" };
int numberOfFruits = fruits.Count(s => s.First()== ‘a’);

Слайд 23

Метод Enumerable.First

public static TSource First (this System.Collections.Generic.IEnumerable source);

int[] numbers = { 9,

Метод Enumerable.First public static TSource First (this System.Collections.Generic.IEnumerable source); int[] numbers =
34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
int first = numbers.First();
Console.WriteLine(first);

Слайд 24

Метод Enumerable.First

public static TSource First (this System.Collections.Generic.IEnumerable source, Func predicate);

int[] numbers =

Метод Enumerable.First public static TSource First (this System.Collections.Generic.IEnumerable source, Func predicate); int[]
{ 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
int first = numbers.First(number => number > 80);
Console.WriteLine(first);

Слайд 25

Метод Enumerable.FirstOrDefault

public static TSource FirstOrDefault (this System.Collections.Generic.IEnumerable source, Func predicate);

string[] names =

Метод Enumerable.FirstOrDefault public static TSource FirstOrDefault (this System.Collections.Generic.IEnumerable source, Func predicate); string[]
{ "Hartono, Tommy", "Adams, Terry", "Andersen, Henriette Thaulow", "Hedlund, Magnus", "Ito, Shu" };
string firstLongName = names.FirstOrDefault(name => name.Length > 20);
Console.WriteLine("The first long name is '{0}'.", firstLongName);

Слайд 26

Метод Enumerable.Last

int[] numbers = { 9, 34, 65, 92, 87, 435, 3,

Метод Enumerable.Last int[] numbers = { 9, 34, 65, 92, 87, 435,
54,
83, 23, 87, 67, 12, 19 };
int last = numbers.Last();

int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 67, 12, 19 };
int last = numbers.Last(num => num > 80);

Слайд 27

Метод Enumerable.LastOrDefault

string[] fruits = { };
string last = fruits.LastOrDefault();
Console.WriteLine(
String.IsNullOrEmpty(last) ? "

Метод Enumerable.LastOrDefault string[] fruits = { }; string last = fruits.LastOrDefault(); Console.WriteLine(
is null or empty>" : last);

double[] numbers = { 49.6, 52.3, 51.0, 49.4, 50.2, 48.3 };
double last50 = numbers.LastOrDefault(n => Math.Round(n) == 50.0);

Слайд 28

Метод Enumerable.LastOrDefault

double last40 = numbers.LastOrDefault(n => Math.Round(n) == 40.0);
Console.WriteLine( "The last

Метод Enumerable.LastOrDefault double last40 = numbers.LastOrDefault(n => Math.Round(n) == 40.0); Console.WriteLine( "The
number that rounds to 40 is {0}.", last40 == 0.0 ? "" : last40.ToString());

Слайд 29

Метод Enumerable.Sum

public static float Sum (this System.Collections.Generic.IEnumerable source);

List numbers = new List

Метод Enumerable.Sum public static float Sum (this System.Collections.Generic.IEnumerable source); List numbers =
{ 43.68F, 1.25F, 583.7F, 6.5F };
float sum = numbers.Sum();
Console.WriteLine("The sum of the numbers is {0}.", sum);

Слайд 30

Метод Enumerable.Sum

public static float Sum (this System.Collections.Generic.IEnumerable source, Func selector);

Метод Enumerable.Sum public static float Sum (this System.Collections.Generic.IEnumerable source, Func selector);

Слайд 31

Метод Enumerable.Sum

List packages = new List {
new Package { Company

Метод Enumerable.Sum List packages = new List { new Package { Company
= "Vineyard", Weight = 25.2 },
new Package { Company = "Lucerne", Weight = 18.7},
new Package { Company = "Wingtip Toys", Weight = 6.0 },
new Package { Company = "Adventure", Weight = 33.8 } };
double totalWeight = packages.Sum(pkg => pkg.Weight);
Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

Слайд 32

Метод Enumerable.Average

public static int Average (this System.Collections.Generic.IEnumerable source);

List grades = new List

Метод Enumerable.Average public static int Average (this System.Collections.Generic.IEnumerable source); List grades =
{ 78, 92, 100, 37, 81 };
double average = grades.Average();
Console.WriteLine("The average grade is {0}.", average);

Слайд 33

Метод Enumerable.Average

public static double Average (this System.Collections.Generic.IEnumerable source, Func selector);

string[] numbers =

Метод Enumerable.Average public static double Average (this System.Collections.Generic.IEnumerable source, Func selector); string[]
{ "10007", "37", "299846234235" };
double average = numbers.Average(num => Convert.ToInt64(num));
Console.WriteLine("The average is {0}.", average);

Слайд 34

Метод Enumerable.Min

public static decimal Min (this System.Collections.Generic.IEnumerable source);

double[] doubles = { 1.5E+104,

Метод Enumerable.Min public static decimal Min (this System.Collections.Generic.IEnumerable source); double[] doubles =
9E+103, -2E+103 };
double min = doubles.Min();
Console.WriteLine("The smallest number is {0}.", min);

Слайд 35

Метод Enumerable.Min

public static TResult Min (this System.Collections.Generic.IEnumerable source, Func selector);

double[] doubles =

Метод Enumerable.Min public static TResult Min (this System.Collections.Generic.IEnumerable source, Func selector); double[]
{ 1.5E+104, 9E+103, -2E+103 };
double min = doubles.Min(x => Math.Abs(x));
Console.WriteLine("The smallest absolute is {0}.", min);

Слайд 36

Метод Enumerable.Max

public static decimal Max (this System.Collections.Generic.IEnumerable source);

double[] doubles = { 1.5E+104,

Метод Enumerable.Max public static decimal Max (this System.Collections.Generic.IEnumerable source); double[] doubles =
9E+103, -2E+103 };
double min = doubles.Max();
Console.WriteLine("The biggest number is {0}.", max);

Слайд 37

Метод Enumerable.Max

public static TResult Max (this System.Collections.Generic.IEnumerable source, Func selector);

double[] doubles =

Метод Enumerable.Max public static TResult Max (this System.Collections.Generic.IEnumerable source, Func selector); double[]
{ 1.5E+104, 9E+103, -2E+103 };
double min = doubles.Max(x => Math.Abs(x));
Console.WriteLine("The biggest absolute is {0}.", min);

Слайд 38

Метод ElementAt

public static TSource ElementAt (this System.Collections.Generic.IEnumerable source, int index);

Метод ElementAt public static TSource ElementAt (this System.Collections.Generic.IEnumerable source, int index);

Слайд 39

Метод ElementAt

string[] names = { "Hartono, Tommy", "Adams, Terry", "Andersen, Henriette Thaulow",

Метод ElementAt string[] names = { "Hartono, Tommy", "Adams, Terry", "Andersen, Henriette
"Hedlund, Magnus", "Ito, Shu" };
Random random = new Random(DateTime.Now.Millisecond);
string name = names.ElementAt(random.Next(0, names.Length));
Console.WriteLine("The name chosen at random is '{0}'.", name);

Слайд 40

Метод ElementAtOrDefault

public static TSource ElementAtOrDefault (this System.Collections.Generic.IEnumerable source, int index);

Метод ElementAtOrDefault public static TSource ElementAtOrDefault (this System.Collections.Generic.IEnumerable source, int index);

Слайд 41

Метод ElementAtOrDefault

int index = 20;
string name = names.ElementAtOrDefault(index);
Console.WriteLine("The name chosen at index

Метод ElementAtOrDefault int index = 20; string name = names.ElementAtOrDefault(index); Console.WriteLine("The name
{0} is '{1}'.", index, String.IsNullOrEmpty(name) ? "" : name);

Слайд 42

Метод Reverse

public static System.Collections.Generic.IEnumerable Reverse (this System.Collections.Generic.IEnumerable source);

Метод Reverse public static System.Collections.Generic.IEnumerable Reverse (this System.Collections.Generic.IEnumerable source);

Слайд 43

Метод Reverse

char[] apple = { 'a', 'p', 'p', 'l', 'e' };
char[] reversed

Метод Reverse char[] apple = { 'a', 'p', 'p', 'l', 'e' };
= apple.Reverse().ToArray();
foreach (char chr in reversed)
{
Console.Write(chr + " ");
}
Console.WriteLine();

Слайд 44

public static System.Linq.IOrderedEnumerable OrderBy (this System.Collections.Generic.IEnumerable source, Func keySelector);

Метод Enumerable.OrderBy

public static System.Linq.IOrderedEnumerable OrderBy (this System.Collections.Generic.IEnumerable source, Func keySelector); Метод Enumerable.OrderBy

Слайд 45

public static void OrderByEx1()
{
Pet[] pets = { new Pet { Name="Barley",

public static void OrderByEx1() { Pet[] pets = { new Pet {
Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
IEnumerable query = pets.OrderBy(pet => pet.Age);
foreach (Pet pet in query)
{
Console.WriteLine("{0} - {1}", pet.Name, pet.Age);
}
}

Метод Enumerable.OrderBy

Слайд 46

public static System.Linq.IOrderedEnumerable OrderBy (this System.Collections.Generic.IEnumerable source, Func keySelector, System.Collections.Generic.IComparer comparer);

Метод Enumerable.OrderBy

public static System.Linq.IOrderedEnumerable OrderBy (this System.Collections.Generic.IEnumerable source, Func keySelector, System.Collections.Generic.IComparer comparer); Метод Enumerable.OrderBy

Слайд 47

public static System.Linq.IOrderedEnumerable OrderByDescending (this System.Collections.Generic.IEnumerable source, Func keySelector, System.Collections.Generic.IComparer comparer);

Метод Enumerable.OrderByDescending

public static System.Linq.IOrderedEnumerable OrderByDescending (this System.Collections.Generic.IEnumerable source, Func keySelector, System.Collections.Generic.IComparer comparer); Метод Enumerable.OrderByDescending

Слайд 48

public static System.Linq.IOrderedEnumerable OrderByDescending (this System.Collections.Generic.IEnumerable source, Func keySelector);

Метод Enumerable.OrderByDescending

public static System.Linq.IOrderedEnumerable OrderByDescending (this System.Collections.Generic.IEnumerable source, Func keySelector); Метод Enumerable.OrderByDescending

Слайд 49

public static System.Linq.IOrderedEnumerable ThenBy (this System.Linq.IOrderedEnumerable source, Func keySelector, System.Collections.Generic.IComparer comparer);

Метод Enumerable.ThenBy

public static System.Linq.IOrderedEnumerable ThenBy (this System.Linq.IOrderedEnumerable source, Func keySelector, System.Collections.Generic.IComparer comparer); Метод Enumerable.ThenBy

Слайд 50

public static System.Linq.IOrderedEnumerable ThenBy (this System.Linq.IOrderedEnumerable source, Func keySelector);

Метод Enumerable.ThenBy

public static System.Linq.IOrderedEnumerable ThenBy (this System.Linq.IOrderedEnumerable source, Func keySelector); Метод Enumerable.ThenBy

Слайд 51

string[] fruits = { "grape", "passionfruit", "banana", "mango", "orange", "raspberry", "apple", "blueberry"

string[] fruits = { "grape", "passionfruit", "banana", "mango", "orange", "raspberry", "apple", "blueberry"
};
IEnumerable query = fruits.OrderBy(fruit => fruit.Length).ThenBy(fruit => fruit);
foreach (string fruit in query)
{
Console.WriteLine(fruit);
}

Метод Enumerable.ThenBy

Слайд 52

public class CaseInsensitiveComparer : IComparer
{
public int Compare(string x, string y)
{

public class CaseInsensitiveComparer : IComparer { public int Compare(string x, string y)
return string.Compare(x, y, true);
}
}

Метод Enumerable.ThenByDescending

Слайд 53

public static void ThenByDescendingEx1()
{ string[] fruits = { "apPLe", "baNanA", "apple", "APple",

public static void ThenByDescendingEx1() { string[] fruits = { "apPLe", "baNanA", "apple",
"orange", "BAnana", "ORANGE", "apPLE" };
IEnumerable query = fruits
.OrderBy(fruit => fruit.Length)
.ThenByDescending(fruit => fruit, new CaseInsensitiveComparer());
}

Метод Enumerable.ThenByDescending

Слайд 54

Метод Take

public static System.Collections.Generic.IEnumerable Take (this System.Collections.Generic.IEnumerable source, int count);

Метод Take public static System.Collections.Generic.IEnumerable Take (this System.Collections.Generic.IEnumerable source, int count);

Слайд 55

Метод Take

int[] grades = { 59, 82, 70, 56, 92, 98, 85

Метод Take int[] grades = { 59, 82, 70, 56, 92, 98,
};
IEnumerable topThreeGrades =
grades.OrderByDescending(grade => grade).Take(3);
Console.WriteLine("The top three grades are:");
foreach (int grade in topThreeGrades)
{
Console.WriteLine(grade);
}

Слайд 56

Метод TakeWhile

public static System.Collections.Generic.IEnumerable TakeWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Метод TakeWhile public static System.Collections.Generic.IEnumerable TakeWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Слайд 57

Метод TakeWhile

string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" };
IEnumerable

Метод TakeWhile string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape"
query = fruits.TakeWhile(fruit => String.Compare("orange", fruit, true) != 0);
foreach (string fruit in query)
{
Console.WriteLine(fruit);
}

Слайд 58

Метод TakeWhile

public static System.Collections.Generic.IEnumerable TakeWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Метод TakeWhile public static System.Collections.Generic.IEnumerable TakeWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Слайд 59

Метод TakeWhile

string[] fruits = { "apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape",

Метод TakeWhile string[] fruits = { "apple", "passionfruit", "banana", "mango", "orange", "blueberry",
"strawberry" };
IEnumerable query =
fruits.TakeWhile((fruit, index) => fruit.Length >= index);
foreach (string fruit in query)
{
Console.WriteLine(fruit);
}

Слайд 60

Метод Skip

public static System.Collections.Generic.IEnumerable Skip (this System.Collections.Generic.IEnumerable source, int count);

Метод Skip public static System.Collections.Generic.IEnumerable Skip (this System.Collections.Generic.IEnumerable source, int count);

Слайд 61

Метод Skip

int[] grades = { 59, 82, 70, 56, 92, 98, 85

Метод Skip int[] grades = { 59, 82, 70, 56, 92, 98,
};
IEnumerable lowerGrades =
grades.OrderByDescending(g => g).Skip(3);
Console.WriteLine("All grades except the top three are:");
foreach (int grade in lowerGrades)
{
Console.WriteLine(grade);
}

Слайд 62

Метод SkipWhile

public static System.Collections.Generic.IEnumerable SkipWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Метод SkipWhile public static System.Collections.Generic.IEnumerable SkipWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Слайд 63

Метод SkipWhile

int[] grades = { 59, 82, 70, 56, 92, 98, 85

Метод SkipWhile int[] grades = { 59, 82, 70, 56, 92, 98,
};
IEnumerable lowerGrades =
grades
.OrderByDescending(grade => grade)
.SkipWhile(grade => grade >= 80);
Console.WriteLine("All grades below 80:");
foreach (int grade in lowerGrades)
{
Console.WriteLine(grade);
}

Слайд 64

Метод SkipWhile
public static System.Collections.Generic.IEnumerable SkipWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Метод SkipWhile public static System.Collections.Generic.IEnumerable SkipWhile (this System.Collections.Generic.IEnumerable source, Func predicate);

Слайд 65

Метод SkipWhile

int[] amounts = { 5000, 2500, 9000, 8000, 6500, 4000, 1500,

Метод SkipWhile int[] amounts = { 5000, 2500, 9000, 8000, 6500, 4000,
5500 };
IEnumerable query =
amounts.SkipWhile((amount, index) => amount > index * 1000);
foreach (int amount in query)
{
Console.WriteLine(amount);
}

Слайд 66

Метод SkipLast

public static System.Collections.Generic.IEnumerable SkipLast (this System.Collections.Generic.IEnumerable source, int count);

Метод SkipLast public static System.Collections.Generic.IEnumerable SkipLast (this System.Collections.Generic.IEnumerable source, int count);

Слайд 67

Метод Select

public static System.Collections.Generic.IEnumerable Select (this System.Collections.Generic.IEnumerable source, Func selector);

Метод Select public static System.Collections.Generic.IEnumerable Select (this System.Collections.Generic.IEnumerable source, Func selector);

Слайд 68

Метод Select

string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" };
var

Метод Select string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape"
query =
fruits.Select((fruit, index) =>
new { index, str = fruit.Substring(0, index) });
foreach (var obj in query)
{
Console.WriteLine("{0}", obj);
}

Слайд 69

Метод Select

public static System.Collections.Generic.IEnumerable Select (this System.Collections.Generic.IEnumerable source, Func selector);

Метод Select public static System.Collections.Generic.IEnumerable Select (this System.Collections.Generic.IEnumerable source, Func selector);

Слайд 70

Метод Select

IEnumerable squares =
Enumerable.Range(1, 10).Select(x => x * x);
foreach (int num

Метод Select IEnumerable squares = Enumerable.Range(1, 10).Select(x => x * x); foreach
in squares)
{
Console.WriteLine(num);
}

Слайд 71

Метод SelectMany

public static System.Collections.Generic.IEnumerable SelectMany (this System.Collections.Generic.IEnumerable source, Func> selector);

Метод SelectMany public static System.Collections.Generic.IEnumerable SelectMany (this System.Collections.Generic.IEnumerable source, Func > selector);

Слайд 72

Метод SelectMany

PetOwner[] petOwners =
{ new PetOwner { Name="Higa, Sidney",
Pets = new

Метод SelectMany PetOwner[] petOwners = { new PetOwner { Name="Higa, Sidney", Pets
List{ "Scruffy", "Sam" } },
new PetOwner { Name="Ashkenazi, Ronen",
Pets = new List{ "Walker", "Sugar" } },
new PetOwner { Name="Price, Vernette",
Pets = new List{ "Scratches", "Diesel" } } };

Слайд 73

Метод SelectMany

IEnumerable query1 = petOwners.SelectMany(petOwner => petOwner.Pets);
IEnumerable> query2 =
petOwners.Select(petOwner => petOwner.Pets);

Метод SelectMany IEnumerable query1 = petOwners.SelectMany(petOwner => petOwner.Pets); IEnumerable > query2 = petOwners.Select(petOwner => petOwner.Pets);

Слайд 74

Метод SelectMany

var query = petOwners .SelectMany(petOwner => petOwner.Pets, (petOwner, petName) => new

Метод SelectMany var query = petOwners .SelectMany(petOwner => petOwner.Pets, (petOwner, petName) =>
{ petOwner, petName })
IEnumerable query = petOwners.SelectMany((petOwner, index) => petOwner.Pets.Select(pet => index + pet));

Слайд 75

Метод Zip

public static System.Collections.Generic.IEnumerable Zip (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, Func resultSelector);

Метод Zip public static System.Collections.Generic.IEnumerable Zip (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, Func resultSelector);

Слайд 76

Метод Zip

int[] numbers = { 1, 2, 3, 4 };
string[] words =

Метод Zip int[] numbers = { 1, 2, 3, 4 }; string[]
{ "one", "two", "three" };
var numbersAndWords = numbers.Zip(words, (first, second) => first + " " + second);
foreach (var item in numbersAndWords)
Console.WriteLine(item);

Слайд 77

Метод Zip

public static System.Collections.Generic.IEnumerable> Zip (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second);

Метод Zip public static System.Collections.Generic.IEnumerable > Zip (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second);

Слайд 78

Метод Disctinct

public static System.Collections.Generic.IEnumerable Distinct (this System.Collections.Generic.IEnumerable source);

Метод Disctinct public static System.Collections.Generic.IEnumerable Distinct (this System.Collections.Generic.IEnumerable source);

Слайд 79

Метод Disctinct

List ages = new List { 21, 46, 46, 55, 17,

Метод Disctinct List ages = new List { 21, 46, 46, 55,
21, 55, 55 };
IEnumerable distinctAges = ages.Distinct();
Console.WriteLine("Distinct ages:");
foreach (int age in distinctAges)
{
Console.WriteLine(age);
}

Слайд 80

Метод Disctinct

public class Product : IEquatable
{
public string Name { get; set;

Метод Disctinct public class Product : IEquatable { public string Name {
}
public int Code { get; set; }
public bool Equals(Product other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return true;
return Code.Equals(other.Code) && Name.Equals(other.Name);
}
Имя файла: LINQ.pptx
Количество просмотров: 21
Количество скачиваний: 0