1

I have the following method in my code

public override string ToString()
{
    return string.Format(
        CultureInfo.InvariantCulture, "{{0}} Text = \"{1}\"", Matrix, Text);
}

Matrix is a struct and Text is a string.

However, Code Analysis gives me following warning for the method:

CA2241
Provide correct arguments to formatting methods
Method 'XX.ToString()' calls
'string.Format(IFormatProvider, string, params object[])'
and does not provide a format item for argument "1".
The provided format string is: '"{{0}} Text = \"{1}\""' 

For me it seems like the code of ToString() is valid. What I am missing?

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130

1 Answers1

1

It looks like you are escaping your curly braces for {0}. Try {{{0}}}.

Tallek
  • 1,575
  • 15
  • 22