Jannik
Jannik

Reputation: 2429

Why does ReSharper warn at Char.ToString() when not specifying CultureInfo explicitly?

I was wondering why ReSharper does warn me, when I'm trying to convert a char to a string without giving a specific culture info.

Is there any case, where it could be converted differently on two systems?

Example:

var str = ' '.ToString();

The following ReSharper warning will pop up by default:

Specify a culture in string conversion explicitly.

Upvotes: 8

Views: 311

Answers (2)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391634

This is because ReSharper sees that the type implements IConvertible which has ToString(IFormatProvider).

System.Char by itself does not expose a public method with that signature, even though the documentation indicates it does:

Char.ToString overloads

If you look at the overload with the IFormatProvider parameter you will see this notice:

Implements
IConvertible.ToString(IFormatProvider)

and this remark:

The provider parameter is ignored; it does not participate in this operation.

ReSharper just notices the presence of that method, and the call to ToString without a IFormatProvider and thus complains, in this case you can safely disregard it.

Upvotes: 10

tdat00
tdat00

Reputation: 830

I found this http://csharpindepth.com/Articles/General/Strings.aspx

Some of the oddities of Unicode lead to oddities in string and character handling. Many of the string methods are culture-sensitive - in other words, what they do depends on the culture of the current thread. For example, what would you expect "i".toUpper() to return? Most people would say "I", but in Turkish the correct answer is "İ" (Unicode U+0130, "Latin capital I with dot above")

Upvotes: -2

Related Questions