Содержание

Слайд 2

Метод 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);

Слайд 3

Метод 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);

Слайд 4

Метод 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);

Слайд 5

Метод 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);

Слайд 6

Метод 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);

Слайд 7

Метод 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();

Слайд 8

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

Слайд 9

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

Слайд 10

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

Слайд 11

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

Слайд 12

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

Слайд 13

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

Слайд 14

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

Слайд 15

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

Слайд 16

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

Слайд 17

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

Слайд 18

Метод 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);

Слайд 19

Метод 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);
}

Слайд 20

Метод 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);

Слайд 21

Метод 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);
}

Слайд 22

Метод 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);

Слайд 23

Метод 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);
}

Слайд 24

Метод 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);

Слайд 25

Метод 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);
}

Слайд 26

Метод 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);

Слайд 27

Метод 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);
}

Слайд 28

Метод 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);

Слайд 29

Метод 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);
}

Слайд 30

Метод 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);

Слайд 31

Метод 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);

Слайд 32

Метод 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);
}

Слайд 33

Метод 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);

Слайд 34

Метод 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);
}

Слайд 35

Метод 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);

Слайд 36

Метод 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" } } };

Слайд 37

Метод 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);

Слайд 38

Метод 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));

Слайд 39

Метод 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);

Слайд 40

Метод 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);

Слайд 41

Метод 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);

Слайд 42

Метод 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);

Слайд 43

Метод 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);
}

Слайд 44

Метод 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);
}
Имя файла: LINQ2.pptx
Количество просмотров: 37
Количество скачиваний: 0