I am having a strange problem with String.Format(). I need to format two hexadecimal numbers with leading zeros to enter up to 8 digits. However, it only works for the first argument ( {0:X8}). For the second argument ( {1:X8}), only "X8" is printed.
This is my code:
public struct DataDirectory
{
public uint VirtualAddress
{
get;
internal set;
}
public uint Size
{
get;
internal set;
}
public override string ToString()
{
return String.Format("{{VirtualAddress=0x{0:X8},Size=0x{1:X8}}}", VirtualAddress, Size);
}
}
The debugger output prints this:

EDIT: It seems to work if I remove the curly braces at the beginning and end of the format string, but then I miss the lines that are returned from ToString()(the debugger still adds them to the QuickWatch window):
return String.Format("VirtualAddress=0x{0:X8},Size=0x{1:X8}", VirtualAddress, Size);
Is it possible to format two hexadecimal numbers with String.Format()?