Содержание

Слайд 2

Метод Union

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

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

Слайд 3

Метод Union

int[] ints1 = { 5, 3, 9, 7, 5, 9, 3,

Метод Union int[] ints1 = { 5, 3, 9, 7, 5, 9,
7 };
int[] ints2 = { 8, 3, 6, 4, 4, 9, 1, 0 };
IEnumerable union = ints1.Union(ints2);
foreach (int num in union)
{
Console.Write("{0} ", num);
}

Слайд 4

Метод Union

public bool Equals(ProductA other)
{
if (other is null)
return false;

Метод Union public bool Equals(ProductA other) { if (other is null) return
return this.Name == other.Name && this.Code == other.Code;
}
public override bool Equals(object obj) => Equals(obj as ProductA);
public override int GetHashCode() => (Name, Code).GetHashCode();

Слайд 5

Метод Union
IEnumerable union =
store1.Union(store2);
foreach (var product in union)
Console.WriteLine(product.Name + "

Метод Union IEnumerable union = store1.Union(store2); foreach (var product in union) Console.WriteLine(product.Name
" + product.Code);

Слайд 6

Метод Intersect

public static System.Collections.Generic.IEnumerable Intersect (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer comparer);

Метод Intersect public static System.Collections.Generic.IEnumerable Intersect (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer comparer);

Слайд 7

Метод Intersect

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

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

Слайд 8

Метод Except

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

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

Слайд 9

Метод Except

double[] numbers1 = { 2.0, 2.0, 2.1, 2.2, 2.3, 2.3, 2.4,

Метод Except double[] numbers1 = { 2.0, 2.0, 2.1, 2.2, 2.3, 2.3,
2.5 };
double[] numbers2 = { 2.2 };
IEnumerable onlyInFirstSet = numbers1.Except(numbers2);
foreach (double number in onlyInFirstSet)
Console.WriteLine(number);

Слайд 10

Метод Except

public static System.Collections.Generic.IEnumerable Except (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer comparer);

Метод Except public static System.Collections.Generic.IEnumerable Except (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer comparer);

Слайд 11

Метод Contains

public static bool Contains (this System.Collections.Generic.IEnumerable source, TSource value);
public static bool

Метод Contains public static bool Contains (this System.Collections.Generic.IEnumerable source, TSource value); public
Contains (this System.Collections.Generic.IEnumerable source, TSource value, System.Collections.Generic.IEqualityComparer comparer);

Слайд 12

Метод Single

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

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

Слайд 13

Метод Single

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

Метод Single string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape"
fruit1 = fruits.Single(fruit => fruit.Length > 10);
Console.WriteLine(fruit1);

Слайд 14

Метод Single

string[] fruits1 = { "orange" };
string fruit1 = fruits1.Single();
Console.WriteLine(fruit1);

Метод Single string[] fruits1 = { "orange" }; string fruit1 = fruits1.Single(); Console.WriteLine(fruit1);

Слайд 15

Метод SingleOrDefault

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

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

Слайд 16

Метод Any

public static bool Any (this System.Collections.Generic.IEnumerable source);
List numbers = new List

Метод Any public static bool Any (this System.Collections.Generic.IEnumerable source); List numbers =
{ 1, 2 };
bool hasElements = numbers.Any();
Console.WriteLine("The list {0} empty.",
hasElements ? "is not" : "is");

Слайд 17

Метод Any

public static bool Any (this System.Collections.Generic.IEnumerable source, Func predicate);
Pet[] pets =

Метод Any public static bool Any (this System.Collections.Generic.IEnumerable source, Func predicate); Pet[]
{
new Pet { Name="Barley", Age=8, Vaccinated=true },
new Pet { Name="Boots", Age=4, Vaccinated=false },
new Pet { Name="Whiskers", Age=1, Vaccinated=false }
};
bool unvaccinated = pets.Any(p => p.Age > 1 && p.Vaccinated == false);

Слайд 18

Метод All

public static bool All (this System.Collections.Generic.IEnumerable source, Func predicate);
Pet[] pets =

Метод All public static bool All (this System.Collections.Generic.IEnumerable source, Func predicate); Pet[]
{
new Pet { Name="Barley", Age=10 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=6 } };
bool allStartWithB = pets.All(pet => pet.Name.StartsWith("B"));

Слайд 19

Метод SequenceEqual

public static bool SequenceEqual (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second);
List pets1 =

Метод SequenceEqual public static bool SequenceEqual (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second); List
new List { pet1, pet2 };
List pets2 = new List { pet1, pet2 };
bool equal = pets1.SequenceEqual(pets2);

Слайд 20

Метод SequenceEqual

public static bool SequenceEqual (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer comparer);

Метод SequenceEqual public static bool SequenceEqual (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer comparer);

Слайд 21

Метод SequenceEqual

class ProductComparer : IEqualityComparer
{
public bool Equals(Product x, Product y)
{
if

Метод SequenceEqual class ProductComparer : IEqualityComparer { public bool Equals(Product x, Product
(Object.ReferenceEquals(x, y)) return true;
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
return x.Code == y.Code && x.Name == y.Name;
}

Слайд 22

Метод SequenceEqual (продолжение)

public int GetHashCode(Product product)
{
if (Object.ReferenceEquals(product, null)) return 0;
int

Метод SequenceEqual (продолжение) public int GetHashCode(Product product) { if (Object.ReferenceEquals(product, null)) return
hashProductName = product.Name == null ? 0 : product.Name.GetHashCode();
int hashProductCode = product.Code.GetHashCode();
return hashProductName ^ hashProductCode;
}
}

Слайд 23

Метод OfType

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

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

Слайд 24

Метод OfType

System.Collections.ArrayList fruits = new System.Collections.ArrayList(4);
fruits.Add("Mango");fruits.Add("Orange");
fruits.Add("Apple");fruits.Add(3.0);fruits.Add("Banana");
IEnumerable query1 = fruits.OfType();
Console.WriteLine("Elements of type 'string'

Метод OfType System.Collections.ArrayList fruits = new System.Collections.ArrayList(4); fruits.Add("Mango");fruits.Add("Orange"); fruits.Add("Apple");fruits.Add(3.0);fruits.Add("Banana"); IEnumerable query1 =
are:");
foreach (string fruit in query1)
{
Console.WriteLine(fruit);
}

Слайд 25

Метод Cast

public static System.Collections.Generic.IEnumerable Cast (this System.Collections.IEnumerable source);
System.Collections.ArrayList fruits = new System.Collections.ArrayList();

Метод Cast public static System.Collections.Generic.IEnumerable Cast (this System.Collections.IEnumerable source); System.Collections.ArrayList fruits =
fruits.Add("mango"); fruits.Add("apple"); fruits.Add("lemon");
IEnumerable query = fruits.Cast().OrderBy(fruit => fruit).Select(fruit => fruit);

Слайд 26

Метод перевода

public static TSource[] ToArray (…);
public static System.Collections.Generic.Dictionary ToDictionary (…);
public static System.Collections.Generic.List

Метод перевода public static TSource[] ToArray (…); public static System.Collections.Generic.Dictionary ToDictionary (…);
ToList (…);
public static System.Collections.Generic.HashSet ToHashSet (…);

Слайд 27

Метод Aggregate

public static TAccumulate Aggregate (this System.Collections.Generic.IEnumerable source, TAccumulate seed, Func func);
int[]

Метод Aggregate public static TAccumulate Aggregate (this System.Collections.Generic.IEnumerable source, TAccumulate seed, Func
ints = { 4, 8, 8, 3, 9, 0, 7, 8, 2 };
int numEven = ints.Aggregate(0, (total, next) =>
next % 2 == 0 ? total + 1 : total);
Console.WriteLine("The number of even integers is: {0}", numEven);

Слайд 28

Метод Join

public static System.Collections.Generic.IEnumerable Join (this System.Collections.Generic.IEnumerable outer, System.Collections.Generic.IEnumerable inner, Func outerKeySelector,

Метод Join public static System.Collections.Generic.IEnumerable Join (this System.Collections.Generic.IEnumerable outer, System.Collections.Generic.IEnumerable inner, Func
Func innerKeySelector, Func resultSelector);

Слайд 29

Метод Join

List people = new List { magnus, terry, charlotte };
List

Метод Join List people = new List { magnus, terry, charlotte };
pets = new List { barley, boots, whiskers, daisy };
var query = people.Join(pets,
person => person,
pet => pet.Owner,
(person, pet) => new { OwnerName = person.Name, Pet = pet.Name });

Слайд 30

Метод GroupJoin

public static System.Collections.Generic.IEnumerable GroupJoin (this System.Collections.Generic.IEnumerable outer, System.Collections.Generic.IEnumerable inner, Func outerKeySelector,

Метод GroupJoin public static System.Collections.Generic.IEnumerable GroupJoin (this System.Collections.Generic.IEnumerable outer, System.Collections.Generic.IEnumerable inner, Func
Func innerKeySelector, Func,TResult> resultSelector);

Слайд 31

Метод GroupJoin

List people = new List { magnus, terry, charlotte };
List

Метод GroupJoin List people = new List { magnus, terry, charlotte };
pets = new List { barley, boots, whiskers, daisy };
var query = people.GroupJoin(pets,
person => person,
pet => pet.Owner,
(person, petCollection) => new {
OwnerName = person.Name,
Pets = petCollection.Select(pet => pet.Name) });

Слайд 32

Метод GroupBy

public static System.Collections.Generic.IEnumerable> GroupBy (this System.Collections.Generic.IEnumerable source, Func keySelector, Func elementSelector);

Метод GroupBy public static System.Collections.Generic.IEnumerable > GroupBy (this System.Collections.Generic.IEnumerable source, Func keySelector, Func elementSelector);
Имя файла: LINQ3.pptx
Количество просмотров: 34
Количество скачиваний: 0