How to make IEnumerable.Contains case-insensitive?

前端 未结 3 805
走了就别回头了
走了就别回头了 2020-12-09 01:34

Suppose I have a .net Array of strings.

string[] strings = new string[] { \"AbC\", \"123\", \"Xyz\", \"321\" };

If I wanted to see if the a

3条回答
  •  忘掉有多难
    2020-12-09 01:51

    Use overloaded Enumerable.Contains method which accepts equality comparer:

    strings.Contains("ABC", StringComparer.InvariantCultureIgnoreCase)
    

    Also there is strings comparer in box which you can use.

提交回复
热议问题