Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. public string ConvertFileSize(long size)
  2. {
  3. switch (size)
  4. {
  5. case long n when (n < 1024):
  6. return $"{n} Bytes";
  7. case long n when (n >= 1024 && n < Math.Pow(1024, 2)):
  8. return $"{n / 1024:N2} KB";
  9. case long n when (n >= Math.Pow(1024, 2) && n < Math.Pow(1024, 3)):
  10. return $"{n / Math.Pow(1024, 2):N2} MB";
  11. case long n when (n >= Math.Pow(1024, 3)):
  12. return $"{n / Math.Pow(1024, 3):N2} GB";
  13. default:
  14. return size.ToString();
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement