IntPtr and UIntPtr implement IFormattable

IntPtr and UIntPtr now implement IFormattable. Functions that check for IFormattable support may now return different results for these types, because they may pass in a format specifier and a culture.

Change description

In previous versions of .NET, IntPtr and UIntPtr do not implement IFormattable. Functions that check for IFormattable may fall back to just calling IntPtr.ToString or UIntPtr.ToString, which means that format specifiers and cultures are not respected.

In .NET 5 and later versions, IntPtr and UIntPtr implement IFormattable. Functions that check for IFormattable support may now return different results for these types, because they may pass in a format specifier and a culture.

This change impacts scenarios like interpolated strings and Console.WriteLine, among others.

Reason for change

IntPtr and UIntPtr now have language support in C# through the nint and nuint keywords. The backing types were updated to provide near parity (where possible) with functionality exposed by other primitive types, such as System.Int32.

Version introduced

5.0

If you don't want a format specifier or custom culture to be used when displaying values of these types, you can call the IntPtr.ToString() and UIntPtr.ToString() overloads of ToString().

Affected APIs

Not detectable via API analysis.