我正在尝试使用下面的代码将字节转换为 KB/MB/GB,但是,我似乎无法让它工作。配额的值为 60000000000。
public static double BytesToKilobytes(this Int32 bytes)
{
return bytes / 1000d;
}
public static double BytesToMegabytes(this Int32 bytes)
{
return bytes / 1000d / 1000d;
}
public static double BytesToGigabytes(this Int32 bytes)
{
return bytes / 1000d / 1000d / 1000d;
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
XDocument xDocument = XDocument.Parse(e.Result);
listBox1.ItemsSource = from query in xDocument.Descendants("service")
select new Service
{
type = query.Attribute("type").Value,
id = query.Element("id").Value,
plan = query.Element("username").Value,
quota = query.Element("quota").Value.BytesToGigabytes, };
}
上面代码产生的错误是:
“'string' 不包含'BytesToGigabytes' 的定义,并且找不到接受'string' 类型的第一个参数的扩展方法'BytesToGigabytes'(您是否缺少 using 指令或程序集引用?)”