T
thi
Hi,
Just wondering whether there is any filesize format function in c#? The
reason i ask because i want to display the file size just like windows e.g.
100 KB, 1MB, 1GB etc...
I am kind of hoping there is a method already built in c# as currently i
have to write a custom one and it looks like this:
private string formatsizekb(double dsize)
{
const int iKB = 1024;
const long lMB = 1048576;
...
if (dsize < iKB)
return string.format("{0} bytes", dsize);
if (dsize >= iKB && dsize < lMB)
return string.format("{0} KB", dsize/1024);
...
}
This works fine but just thought if there is any better way of doing this.
Thanks in advance
Just wondering whether there is any filesize format function in c#? The
reason i ask because i want to display the file size just like windows e.g.
100 KB, 1MB, 1GB etc...
I am kind of hoping there is a method already built in c# as currently i
have to write a custom one and it looks like this:
private string formatsizekb(double dsize)
{
const int iKB = 1024;
const long lMB = 1048576;
...
if (dsize < iKB)
return string.format("{0} bytes", dsize);
if (dsize >= iKB && dsize < lMB)
return string.format("{0} KB", dsize/1024);
...
}
This works fine but just thought if there is any better way of doing this.
Thanks in advance