Represents binary value with support for simple arithmetic operations.

BinaryUnit OneMB = BinaryUnit.FromMegabytes(1);
BinaryUnit ThreeMB = BinaryUnit.FromMegabytes(3);
string s= (OneMB + ThreeMB).ToString(); //returns "4 MB"
BinaryUnit unit = BinaryUnit.FromKilobytes(1333);
string s = unit.ToString(1); //returns "1.3 MB" - 1 digit precision
string s  =unit.ToString("000.0"); //returns 001.3 - custom string formatting

For valid format string check Custom Numeric Format Strings on MSDN.

Last edited Aug 23, 2011 at 10:00 AM by mgrzyb, version 1

Comments

No comments yet.