private string ReadableFileSize()
{
LoadFileInfo();
var length = _info.Length;
if (length < Math.Pow(1024, 1))
return length + " B"; //lower than 1kb
if (length < Math.Pow(1024, 2))
return TrimSize(length, 1) + " KB"; //lower than 1mb
if (length < Math.Pow(1024, 3))
return TrimSize(length, 2) + " MB"; //lower than 1gb
if (length < Math.Pow(1024, 4))
return TrimSize(length, 3) + " GB"; //lower than 1tb
return length + " TB";//return size in tb
}
1 ответ
private string GetFileSize()
{
LoadFileInfo();
var length = _info.Length;
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
var order = 0;
while (length >= 1024 && order < sizes.Length - 1)
{
order++;
length /= 1024;
}
var result = $"{length:0.##} {sizes[order]}";
return result;
}
if
вдруг и вовсе не нужны, да и код кажется более логичным, да?)