Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 509
Jannik Avatar asked Jan 11 '16 08:01

Jannik


1 Answers

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.

like image 168
Lasse V. Karlsen Avatar answered Nov 15 '22 17:11

Lasse V. Karlsen