How to ignore the case sensitivity in List

前端 未结 11 936
旧时难觅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条回答
  •  不知归路
    2020-11-30 10:06

    The FindAll does enumeration of the entire list.

    the better approach would be to break after finding the first instance.

    bool found = list.FirstOrDefault(x=>String.Equals(x, searchKeyWord, Stringcomparison.OrdinalIgnoreCase) != null;

提交回复
热议问题