Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. bool collectionModified = false;
  2. if(collectionNeedsModification)
  3. {
  4. modifyCollection();
  5. collectionModified = true;
  6. }
  7.  
  8. var aggregationResult = from a in
  9. (from b in collection
  10. where b.SatisfysCondition)
  11. .Aggregate(aggregationFunction)
  12. select a.NeededValue;
  13.  
  14. if(collectionModified)
  15. modifyCollection();
  16.  
  17. return aggregationResult;
  18.  
  19. var aggregationResult = (from a in
  20. (from b in collection
  21. where b.SatisfysCondition)
  22. .Aggregate(aggregationFunction)
  23. select a.NeededValue).ToArray();
  24.  
  25. foreach (var result in aggregationResult)
  26. {
  27. // Deliberately empty; simply forcing evaluation of the sequence.
  28. }
  29.  
  30. aggregationResult.Run();
  31.  
  32. public static MyLinqExtensions
  33. {
  34. public static void Run<T>(this IEnumerable<T> e)
  35. {
  36. foreach (var _ in e);
  37. }
  38. }
  39.  
  40. var modifiedCollection = ModifyCollection(collection, collectionNeedsModification);
  41.  
  42. var aggregationResult = from a in
  43. (from b in modifiedCollection
  44. where b.SatisfysCondition)
  45. .Aggregate(aggregationFunction)
  46. select a.NeededValue;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement