|
| 1 | +using LearningCSharp.Topics.Domains; |
| 2 | +using LearningCSharp.Topics.LINQ; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +namespace LearningCSharp.Cmd.Series4.LINQPlus |
| 10 | +{ |
| 11 | + public class Tester1 |
| 12 | + { |
| 13 | + public static void Main() |
| 14 | + { |
| 15 | + List<Category> squad = new List<Category>() |
| 16 | + { |
| 17 | + new Category(){ Name = "Jersey" }, |
| 18 | + new Category(){ Name = "Boot" }, |
| 19 | + }; |
| 20 | + |
| 21 | + var squadResult = squad.Last(s => s.Name.Contains("gaby")); |
| 22 | + Console.WriteLine(squadResult); |
| 23 | + |
| 24 | + var name1 = new List<dynamic> { new { Name = "Prolifik", Id = 1 } }; |
| 25 | + var name2 = new List<dynamic> { new { Name = "Lexzy", Id = 2 } }; |
| 26 | + |
| 27 | + var name1Name2 = from n1 in name1 |
| 28 | + join n2 in name2 |
| 29 | + on n1.Id equals n2.Id |
| 30 | + select new { FullName = $"{n1.Name} {n2.Name}" }; |
| 31 | + |
| 32 | + |
| 33 | + foreach (var item in name1Name2) |
| 34 | + { |
| 35 | + Console.WriteLine(item.FullName); |
| 36 | + } |
| 37 | + |
| 38 | + Console.WriteLine("======================"); |
| 39 | + |
| 40 | + List<string> names = new List<string>() |
| 41 | + { |
| 42 | + "Gaby", |
| 43 | + "Prolifik", |
| 44 | + "Lola" |
| 45 | + }; |
| 46 | + |
| 47 | + names.ForEach(n => { Console.WriteLine(n); }); |
| 48 | + |
| 49 | + |
| 50 | + var categories = names.Select(n => new { Name = n }); |
| 51 | + |
| 52 | + |
| 53 | + Console.WriteLine(names.Skip(2).Last()); |
| 54 | + |
| 55 | + var prodList = CollectionManager.GetProduct().GroupBy(p => p.Category); |
| 56 | + |
| 57 | + foreach (var groupKey in prodList) |
| 58 | + { |
| 59 | + Console.Write(groupKey.Key); |
| 60 | + Console.WriteLine("======================"); |
| 61 | + foreach (var item in groupKey) |
| 62 | + { |
| 63 | + Console.WriteLine($"{item.Category}: {item.Name}"); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + Console.Read(); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments