Why avoid string.ToLower() when doing case-insensitive string comparisons?

后端 未结 5 1123
温柔的废话
温柔的废话 2021-01-19 05:38

I have read that when in your application you do a lot of string comparison and using ToLower method, this method is quite costly. I was wondering of anyone could explain to

5条回答
  •  醉梦人生
    2021-01-19 05:56

    See also writing culture-safe managed code for a very good reason why not to use ToLower().

    In particular, see the section on the Turkish "I" - it's caused no end of problems in the past where I work...

    Calling "I".ToLower() won't return "i" if the current culture is Turkish or Azerbaijani. Doing a direct comparison on that will cause problems.

提交回复
热议问题