以下のコードを使用してバイトを 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 ディレクティブまたはアセンブリ参照がありませんか?)」