tags:

views:

86

answers:

1

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.

+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