Is Int32.ToString() culture-specific?

后端 未结 7 1091
名媛妹妹
名媛妹妹 2020-11-30 09:47

I\'m running a beta version of ReSharper, and it\'s giving me warnings for the following code:

int id;
// ...
DoSomethingWith(id.ToString());
7条回答
  •  天涯浪人
    2020-11-30 10:01

    The Operating System allows to change the negative sign for numbers.

    Control panel -> 
       Language and regional settings -> 
             Additional settings -> 
                 Negative sign
    

    So, current culture could have overridden the negative sign. In this case you need to respect the regional settings, this is the reason of the warning. You can also change the negative sign programatically:

        CultureInfo culture = Thread.CurrentThread.CurrentCulture;
        // Make a writable clone
        culture = (CultureInfo) culture.Clone();
        culture.NumberFormat.NegativeSign = "!";
    

提交回复
热议问题