아래 코드를 사용하여 바이트를 KB/MB/GB로 변환하려고하지만 작동하지 않는 것 같습니다. 용량의 값은, 상기 코드는 생성 된 오류 60000000000.확장 메서드가 컴파일되지 않음 ('string'형식에 대한 정의가 없음)
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, };
}
이다
는 " '문자열'BytesToGigabytes '의 정의없이 확장 메소드를 포함하지 않는'BytesToGigabytes '는 제 접수 "문자열"형식의 인수를 찾을 수 있습니다 (지시문이나 어셈블리 참조가 누락 되었습니까?) "
아마도 문제는 아니지만 할당량 값이 60 * 10^9이면 Int32에 맞지 않습니다. Int64 (일명 long)를 사용해야합니다. – Niki