How can I call ToLower() on each string in a collection using LINQ?
c#, linq
Solution
Yes, you can specify an `IEqualityComparer<T>` to the `Contains` method. For example, you could use `StringComparer.CurrentCultureIgnoreCase`:
m_SelectedHandler = m_ListOfHandlers.SingleOrDefault(h => h.CountryNames.Contains(country, StringComparer.CurrentCultureIgnoreCase));
This also avoids the temporary strings created by calling `ToLower`.
Problem
Here is my query: ``` m_SelectedHandler = m_ListOfHandlers.SingleOrDefault(h => h.CountryNames.Contains(country.ToLower()); ``` `country` is a string and an argument to the method containing the assignment above. `CountryNames` is a list of strings. How can I call `ToLower` on each of the strings in `CountryNames` so that I'll get valid matches for this query. Is there a better way to do a case-insensitive compare using LINQ?