class FileSize
{
public enum UNITS { B, KB, MB, GB, TB }
double b = 0;
double kb = 0;
double mb = 0;
double gb = 0;
double tb = 0;
public double B
{
get
{
return this.b;
}
set
{
this.b = value;
this.kb = this.b / 1024;
this.mb = this.kb / 1024;
this.gb = this.mb / 1024;
this.tb = this.gb / 1024;
}
}
public double KB
{
get
{
return this.kb;
}
set
{
this.kb = value;
this.B = this.kb * 1024;
}
}
public double MB
{
get
{
return this.mb;
}
set
{
this.mb = value;
this.KB = this.mb * 1024;
}
}
public double GB
{
get
{
return this.gb;
}
set
{
this.gb = value;
this.MB = this.gb * 1024;
}
}
public double TB
{
get
{
return this.tb;
}
set
{
this.tb = value;
this.GB = this.tb * 1024;
}
}
public FileSize(double size)
{
this.B = size;
}
public override string ToString()
{
string ret = string.Empty;
if (b < 1024D)
{
ret = string.Format("{0}{1}", b, UNITS.B.ToString());
}
else if (kb < 1024D)
{
ret = string.Format("{0}{1}", kb, UNITS.KB.ToString());
}
else if (mb < 1024D)
{
ret = string.Format("{0}{1}", mb, UNITS.MB.ToString());
}
else if (gb < 1024D)
{
ret = string.Format("{0}{1}", gb, UNITS.GB.ToString());
}
else
{
ret = string.Format("{0}{1}", tb, UNITS.TB.ToString());
}
return ret;
}
}
댓글 없음:
댓글 쓰기