Back to Devexpress

Use String.Format

coderushforroslyn-115612-refactoring-assistance-use-string-format.md

latest1.4 KB
Original Source

Use String.Format

  • Aug 03, 2020
  • 2 minutes to read

Purpose

Converts a composed string expression into a single String.Format call. The use of formatted strings increases code readability and allows you to customize value formatting.

Availability

Available when the caret is on a composed string expression or interpolated string.

Usage

  1. Place the caret on a composed string expression.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Use String.Format from the menu.

After execution, the Refactoring replaces the composed string with the String.Format method call.

csharp
for (int i = 2; i < 10; i++) {
    for (int j = i; j < 10; j++) {
        Console.WriteLine(String.Format("{0} * {1} = {2}", i, j, i * j));
    }
}
vb
For i As Integer = 2 To 9
    For j As Integer = i To 9
        Console.WriteLine(String.Format("{0} * {1} = {2}", i, j, i * j))
    Next j
Next i

See Also

Convert to String Interpolation

Use String.IsNullOrEmpty

Use String.Compare

Use String Builder