What is the correct way to compare char ignoring case?

前端 未结 9 2507
不知归路
不知归路 2020-12-01 20:31

I\'m wondering what the correct way to compare two characters ignoring case that will work for all cultures. Also, is Comparer.Default the best way

9条回答
  •  时光说笑
    2020-12-01 21:00

    As I understand it, there isn't really a way that will "work for all cultures". Either you want to compare characters for some kind of internal, non-displayed-to-the-user reason (in which case you should use the InvariantCulture), or you want to use the CurrentCulture of the user. Obviously, using the user's current culture will mean that you will get different results in different locales, but they will be consistent with what your users in those locales will expect.

    Without knowing more about WHY you are comparing two characters, I can't really advise you on which one you should be using.

提交回复
热议问题