Guest User

Untitled

a guest
Sep 25th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. // Good
  2. public static async Task<T> UseTemporary<T>(Func<string, Task<T>> func)
  3. {
  4. var path = Path.GetTempFileName();
  5. try
  6. {
  7. return await func(path);
  8. }
  9. finally
  10. {
  11. File.Delete(path);
  12. }
  13. }
  14.  
  15. // Bad
  16. public static Task<T> UseTemporary<T>(Func<string, Task<T>> func)
  17. {
  18. var path = Path.GetTempFileName();
  19. try
  20. {
  21. return func(path);
  22. }
  23. finally
  24. {
  25. File.Delete(path);
  26. }
  27. }
Add Comment
Please, Sign In to add comment