I have a List with a few strings in it. I want to see if it contains a a string that starts with 'blah' however, I'm not sure how to use the (this IEnumerable source, value):bool overload of List.Contains.
views:
86answers:
1
+13
A:
You can use List.Exists
:
bool result = list.Exists(x => x.StartsWith("blah"));
Or Enumerable.Any
then it works with other collection types too:
bool result = list.Any(x => x.StartsWith("blah"));
Mark Byers
2010-07-04 22:25:32