Содержание
- 2. Составляющие LINQ Автоматические свойства Инициализаторы объектов и коллекций Анонимные типы Методы расширения Лямбда-выражения
- 3. Автоматические свойства private string _firstName; public string firstName { get { return _firstName; } set {
- 4. Автоматические свойства private string _firstName; public string firstName { get { return _firstName; } set {
- 5. Неявно типизированные локальные переменные var i = 5; var s = "Hello"; var d = 1.0;
- 6. Правила неявно типизированных локальных переменных var x; // Ошибка var y = {1, 2, 3}; //
- 7. Инициализаторы объектов public class Car { public string VIN { get; set; } public string Make
- 8. Инициализаторы объектов Car c = new Car(); c.VIN = "ABC123"; c.Make = "Ford"; c.Model = "F-250";
- 9. Инициализаторы объектов Car c = new Car(); c.VIN = "ABC123"; c.Make = "Ford"; c.Model = "F-250";
- 10. Инициализаторы коллекций private List GetCars() { return new List { new Car { VIN = "ABC123",
- 11. Анонимные типы var car = new { Make = "VW", Model = "Bug" };
- 12. Методы расширения public static class MyExtensions { public static bool IsValidEmailAddress(this string s) { Regex regex
- 13. Правила методов расширений Метод расширения и класс, в котором он объявлен, должны быть статическими с модификатором
- 14. Анонимные методы List cars = GetCars(); List filtered = new List (); foreach (Car car in
- 15. Анонимные методы List cars = GetCars(); List filtered = new List (); foreach (Car car in
- 16. Анонимные методы public delegate bool FilterPredicate(Car car); public bool CheckPredicates(Car car, IList predicates) { foreach (FilterPredicate
- 17. Анонимные методы List cars = GetCars(); List predicates = new List (); predicates.Add(delegate(Car car) { return
- 18. Анонимные методы List cars = GetCars(); List predicates = new List (); predicates.Add ((Car car) =>
- 19. Анонимные методы List cars = GetCars(); List predicates = new List (); predicates.Add (car => car.Year
- 20. Лямбда-выражения (string s) => { return s.Length; } (s) => { return s.Length; } () =>
- 21. Архитектура C# .NET Language Integrated Query (LINQ) LINQ to SQL LINQ to Objects LINQ to XML
- 22. LINQ-примеры (Query-синтаксис) var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select
- 23. LINQ-примеры (Query-синтаксис) var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select
- 24. LINQ-примеры (Query-синтаксис) var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select
- 25. LINQ-примеры (Query-синтаксис) var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select
- 26. LINQ-примеры (Query-синтаксис) var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select
- 27. Синтаксис var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select new
- 28. Синтаксис var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select new
- 29. Синтаксис var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select new
- 30. Синтаксис var query = from book in list where book.Category == ".NET" orderby book.NumberOfCopies select new
- 31. Ключевые слова C# LINQ ANSI SQL
- 32. Отложенное выполение string[] colors = { "Red", "Brown", "Orange", "Yellow", "Black", "Green", "White", "Violet", "Blue" };
- 33. Отложенное выполение string[] colors = { "Red", "Brown", "Orange", "Yellow", "Black", "Green", "White", "Violet", "Blue" };
- 34. Query Extension Methods Enumerable static methods Empty var numbers = Enumerable.Empty (); Range var numbers =
- 35. Query Extension Methods All, Any All bool result = GetCars().All(c => c.Year > 1960); Any bool
- 36. Query Extension Methods AsEnumerable public class MyStringList : List { public IEnumerable Where(Predicate filter) { return
- 37. Query Extension Methods AsEnumerable public class MyStringList : List { public IEnumerable Where(Predicate filter) { return
- 38. Query Extension Methods AsQueryable IEnumerable strings = new MyStringList {"orange", "apple", "grape", "pear"}; var querable =
- 39. Query Extension Methods ToArray, ToList int[] scores = { 88, 56, 23, 99, 65, 93, 78,
- 40. Query Extension Methods ToDictionary, ToLookUp var cars = GetCars(); var carsByVin = cars.ToDictionary(c => c.VIN); Car
- 41. Query Extension Methods Cast, OfType int[] scores = {88, 56, 23, 99, 65, 93, 78, 23,
- 42. Query Extension Methods Max, Min, Average, Sum, Count int[] scores = {88, 56, 23, 99, 65,
- 43. Query Extension Methods ElementAt, First, Last int[] scores = {88, 56, 23, 99, 65, 93, 78,
- 44. Query Extension Methods ElementAtOrDefault, FirstOrDefault, LastOrDefault int[] scores = {}; txtLog.WriteLine(scores.ElementAtOrDefault(4)); txtLog.WriteLine(scores.FirstOrDefault()); txtLog.WriteLine(scores.LastOrDefault()); Output: 0 0
- 45. Query Extension Methods Single, SingleOrDefault int[] scores = {88, 56, 23, 99, 65, 93, 78, 23,
- 46. Query Extension Methods DefaultIfEmpty List cars = new List (); IEnumerable oneNullCar = cars.DefaultIfEmpty(); foreach (var
- 47. Query Extension Methods Contains int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23,
- 48. Query Extension Methods Distinct int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23,
- 49. Query Extension Methods Concat int[] lastYearScores = { 88, 56, 23, 99, 65 }; int[] thisYearScores
- 50. Query Extension Methods Except int[] lastYearScores = { 88, 56, 23, 99, 65 }; int[] thisYearScores
- 51. Query Extension Methods Intersect int[] lastYearScores = { 88, 56, 23, 99, 65 }; int[] thisYearScores
- 52. Query Extension Methods Union int[] lastYearScores = { 88, 56, 23, 99, 65, 56 }; int[]
- 53. Query Extension Methods Zip var numbers = Enumerable.Range(1, 1000); var cars = GetCars(); var zip =
- 54. Query Extension Methods Reverse int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23,
- 55. Query Extension Methods SequenceEqual List lastYearScores = new List {93, 78, 23, 99, 91}; List thisYearScores
- 56. Query Extension Methods Skip, SkipWhile int[] scores = { 88, 56, 23, 99, 65, 93, 78,
- 57. Query Extension Methods Take, TakeWhile int[] scores = { 88, 56, 23, 99, 65, 93, 78,
- 58. Query Extension Methods GroupBy var cars = GetCars(); var query = cars.GroupBy(c => c.Make); foreach (IGrouping
- 59. Query Extension Methods OrderBy, OrderByDescending, ThenBy, ThenByDescending var cars = GetCars().OrderBy(c => c.Make) .ThenByDescending(c => c.Model)
- 60. Query Extension Methods Where var cars = GetCars(); foreach (var myCar in cars.Where(c => c.Make ==
- 61. Query Extension Methods Select var vehicles = new List > { Tuple.Create("123", "VW", 1999), Tuple.Create("234", "Ford",
- 62. Query Extension Methods Select var fordCars = vehicles .Where(v => v.Item2 == "Ford") .Select(v => new
- 63. Query Extension Methods Select Output: Car VIN:234 Make:Ford Year:2009 Car VIN:678 Make:Ford Year:2003 Car VIN:999 Make:Ford
- 64. Query Extension Methods Select var fordCars = from v in vehicles let makeYear = v.Item2 +
- 65. Query Extension Methods Select Output: Car VIN:234 MakeYear:Ford 2009 Car VIN:678 MakeYear:Ford 2003 Car VIN:999 MakeYear:Ford
- 66. Query Extension Methods SelectMany var repairs = new List >> { Tuple.Create("ABC123", new List {"Rotate Tires",
- 67. Query Extension Methods SelectMany var query = repairs.SelectMany(t => t.Item2.Select(r => new { VIN = t.Item1,
- 68. Query Extension Methods SelectMany Output: VIN:ABC123 Repair:Rotate Tires VIN:ABC123 Repair:Change oil VIN:DEF123 Repair:Fix Flat VIN:DEF123 Repair:Wash
- 69. Query Extension Methods Join var makes = new string[] { "Audi", "BMW", "Ford", "Mazda", "VW" };
- 70. Query Extension Methods GroupJoin var makes = new string[] { "Audi", "BMW", "Ford", "Mazda", "VW" };
- 71. LINQ Joins public class Repair { public string VIN { get; set; } public string Desc
- 72. LINQ Joins Inner join var cars = GetCars(); var repairs = GetRepairs(); var carsWithRepairs = from
- 73. LINQ Joins Inner join Output: Car VIN:ABC123, Make:Ford, Description:Fix Flat Tire Cost:$15.00 Car VIN:ABC123, Make:Ford, Description:Replace
- 74. LINQ Joins Outer join var carsWithRepairs = from c in cars join r in repairs on
- 75. LINQ Joins Outer join Output: Car VIN:ABC123, Make:Ford, Description:Fix Flat Tire Cost:$15.00 Car VIN:ABC123, Make:Ford, Description:Replace
- 76. LINQ Joins Cross join var cars = GetCars(); var colors = new string[] { "Red", "Blue",
- 77. LINQ Joins Cross join Output: Car VIN:ABC123, Make:Ford, Model:F-250 Color:Blue Car VIN:ABC123, Make:Ford, Model:F-250 Color:Green Car
- 79. Скачать презентацию