IFormattable returns wrong value while using format

36 Views Asked by At

I have tried to format a value in HexaDeciamal format using IFormattable, and String.Format. But both return different values. Please suggest some format to get the value like String.Format. Code :

Console.WriteLine("\nValue :  \t" + string.Format(format, 255));

Result is : "0x00FF" 
object obj = 255;
IFormattable formattableValue = (IFormattable)obj;
string value = formattableValue.ToString(format, null);

Console.WriteLine("\nValue :  \t" + value); 

Result : "25x{5:X4}"

Please let me know if you have any concerns.

Click Here for sample

0

There are 0 best solutions below