Skip to main content

Format item index too large

In This Article

CodeRush Classic shows the Format item index too large code issue if a format item index is greater then or equal to the number of arguments passed to the String.Format.

#Fix

Correct the format item index or add arguments to the String.Format call.

#Purpose

Highlights format items with indices greater then or equal to the number of arguments passed to the String.Format; this action will cause the FormatException exception.

#Example

string fileName = "Settings.xml";
string settingsPath = string.Format("C:\\MyApp\\{0}\\{1}", fileName);

Fix:

string fileName = "Settings.xml";
string subfolder = "Settings;"
string settingsPath = string.Format("C:\\MyApp\\{0}\\{1}", subfolder, fileName);