Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public void StartLoop_InOneLine() => LoopMethod().Loop(FuncBoolToStopLoop());
  2.  
  3. public void StartLoop_InOneLine() => LoopMethod.Loop(FuncBoolToStopLoop());
  4.  
  5. public static class LoopExtensions
  6. {
  7. public static void Loop(this Action method, Func<bool> loopUntil)
  8. {
  9. while(loopUntil.Invoke())
  10. method.Invoke();
  11. }
  12. }
  13.  
  14. public class Looping
  15. {
  16. //what I would like to do
  17. public void StartLoop_InOneLine() => LoopMethod().Loop(FuncBoolToStopLoop());
  18.  
  19. //what I want to achieve, in practice
  20. public void StartLoop_InPractice()
  21. {
  22. Action method = LoopMethod;
  23. Func<bool> loopUntil = FuncBoolToStopLoop;
  24.  
  25. method.Loop(loopUntil);
  26. }
  27.  
  28. private void LoopMethod(){}
  29.  
  30. private bool FuncBoolToStopLoop() => true;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement