What is the correct way to compare char ignoring case?

前端 未结 9 2499
不知归路
不知归路 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:16

    You could try:

        class Test{
        static int Compare(char t, char p){
            return string.Compare(t.ToString(), p.ToString(), StringComparison.CurrentCultureIgnoreCase);
        }
    }
    

    But I doubt this is the "optimal" way to do it, but I'm not all of the cases you need to be checking...

提交回复
热议问题