How to ignore the case sensitivity in List

前端 未结 11 875
旧时难觅i
旧时难觅i 2020-11-30 09:46

Let us say I have this code

string seachKeyword = \"\";
List sl = new List();
sl.Add(\"store\");
sl.Add(\"State\");
sl.Add(\"STAM         


        
11条回答
  •  -上瘾入骨i
    2020-11-30 09:58

    You CAN use Contains by providing the case-insensitive string equality comparer like so:

    if (myList.Contains(keyword, StringComparer.OrdinalIgnoreCase))
    {
        Console.WriteLine("Keyword Exists");
    }
    

提交回复
热议问题