Guest User

Untitled

a guest
Jul 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. var query =
  2. from foo in fooStuff.AsEnumerable()
  3. group foo by foo.Field<Int64>("FooID") into g
  4. select new
  5. {
  6. FooID = g.Key,
  7. FooTier = g.Min(foo => foo.Field<int>("Tier"))
  8. };
  9.  
  10. var query =
  11. from foo in fooStuff
  12. group foo by foo.FooID into g
  13. select new
  14. {
  15. FooID = g.Key,
  16. FooTier = g.Min(foo => foo.Tier)
  17. };
  18.  
  19. var fooList = fooStuff.AsEnumerable().ToList();
  20.  
  21. var list2 =
  22. (from foo in fooStuff.AsEnumerable()
  23. select new {
  24. FooID = foo.Field<Int64>("FooID")
  25. Tier = foo.Field<int>("Tier")
  26. }).ToList();
  27.  
  28. var query =
  29. from foo in list2
  30. group foo by foo.FooID into g
  31. select new
  32. {
  33. FooID = g.Key,
  34. FooTier = g.Min(foo => foo.Tier)
  35. };
  36. var results = query.ToList();
  37.  
  38. public static Dictionary<TKey, List<TSrc>> TestGroupBy<TSrc, TKey>
  39. (this IEnumerable<TSrc> src, Func<TSrc,TKey> groupFunc)
  40. {
  41. var dict= new Dictionary<TKey, List<TSrc>>();
  42.  
  43. foreach (TSrc s in src)
  44. {
  45. TKey key = groupFunc(s);
  46. List<TSrc> list ;
  47.  
  48. if (!dict.TryGetValue(key, out list))
  49. {
  50. list = new List<TSrc>();
  51. dict.Add(key, list);
  52. }
  53. list.Add(s);
  54. }
  55.  
  56. return dict;
  57. }
  58.  
  59. var results = list2.TestGroupBy(r=>r.FooID)
  60. .Select(r=> new { FooID = r.Key, FooTier = r.Value.Min(r1=>r1.Tier)} );
Add Comment
Please, Sign In to add comment