ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Use format specifier in interpolated strings

Last modified: 06 June 2024

This inspection suggests using the full capabilities of string interpolation in C#, including specifying the format and controlling the field width.

In the example below, the original interpolated string includes explicit calls of ToString() and PadLeft(), which could be replaced by the colon : and comma , notations respectively.

In the suggested fix:

  • 3 following the comma , is specifying a fixed width for the conversion. In this context, it will make sure that the string representation of i is at least 3 characters wide.

  • format following the colon : is a placeholder for the specific formatting you want to use.