我有一个连接到 WCF 服务的客户端应用程序,我从服务器获取文件大小作为一个long
值,然后在客户端将其转换为string
它看起来像 ex:52.21 MB
每次用户更改当前目录路径时,应用程序都会获得过多的文件大小。
我的问题:我应该将值从WCF 服务应用程序string
转换为格式,然后将其作为 a 返回给客户端,还是应该将大小作为值返回并让客户端将其转换为格式string
long
string
以其他方式,哪个值在内存中占用更多字节:
long size = 55050240;
string size = "52.5 MB";
long large_size = 56371445760;
string large_size = "52.5 GB";
更新:
我使用这种方法将 long 值转换为字符串格式:
private string ConvertUnit(long source)
{
const int byteConversion = 1024;
double bytes = Convert.ToDouble(source);
if (bytes >= Math.Pow(byteConversion, 3)) //GB Range
{
return string.Concat(Math.Round(bytes / Math.Pow(byteConversion, 3), 2), " GB");
}
else if (bytes >= Math.Pow(byteConversion, 2)) //MB Range
{
return string.Concat(Math.Round(bytes / Math.Pow(byteConversion, 2), 2), " MB");
}
else if (bytes >= byteConversion) //KB Range
{
return string.Concat(Math.Round(bytes / byteConversion, 2), " KB");
}
else //Bytes
{
return string.Concat(bytes, " Bytes");
}
}
简短的问题:哪个需要更多的内存、string
价值或long
价值?