Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApp
  5. {
  6. enum Brand
  7. {
  8. Nike,
  9. Adidas,
  10. Levis
  11. }
  12. class Info
  13. {
  14. public Brand Brand { get; set; }
  15. public int Start { get; set; }
  16. public int End { get; set; }
  17. }
  18. class Program
  19. {
  20. static void Main(string[] args)
  21. {
  22. var list = new Info[]
  23. {
  24. new Info{Brand = Brand.Nike, Start = 0, End = 4},
  25. new Info{Brand = Brand.Adidas, Start = 0, End = 5},
  26. new Info{Brand = Brand.Nike, Start = 4, End = 10},
  27. new Info{Brand = Brand.Levis, Start = 0, End = 3},
  28. new Info{Brand = Brand.Adidas, Start = 5, End = 8}
  29. };
  30. var start = 6;
  31. var end = 10;
  32.  
  33. var result = (
  34. from item in list
  35. group item by item.Brand into g
  36. from subItem in g
  37. where (subItem.Start <= start && subItem.End >= start) || (subItem.Start <= end && subItem.End >= end)
  38. select new
  39. {
  40. Brand = g.Key,
  41. Max = g.Max(x => x.End)
  42. }
  43. ).Distinct();
  44.  
  45. foreach (var item in result.ToList())
  46. Console.WriteLine("{0} - {1}", item.Brand, item.Max);
  47.  
  48. Console.ReadLine();
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement