C# 6 introduced string interpolation and a shorter way to specify the format string.
IntPtr ptr = new IntPtr(0xff);
Console.WriteLine(ptr.ToString()); // 255
Console.WriteLine(ptr.ToString("x")); // ff
Console.WriteLine($"0x{ptr.ToString("x")}"); // 0xff
Console.WriteLine($"0x{ptr:x}"); //0x255
Why the two last lines output a different result ? Am I missing something ?
As a side note here is the source code of IntPtr ToString() in dotnet core :
public unsafe String ToString(String format)
{
#if WIN32
return ((int)m_value).ToString(format, CultureInfo.InvariantCulture);
#else
return ((long)m_value).ToString(format, CultureInfo.InvariantCulture);
#endif
}