An example that uses List.Exists(Predicate match)

Over an internal alias someone asked for an example of List.Exists(Predicate match) … I thought you might find it fun and google might help me find it later when I need it 😉


List<string> l = new List<string>();






//prints "true" as "Red" is in the list

Console.WriteLine(l.Exists(delegate(string s) { return s == "Red"; }));


//prnts "false" as "Pink" is not in the list

Console.WriteLine(l.Exists(delegate(string s) { return s == "Pink"; }));

Comments (6)

  1. Dr. Search says:

    You really should start using Lookout.:-)

  2. Equivalent FindAll and ConvertAll examples:

    A ForEach sample as well:

    Exists is one of those completeness APIs. Not used very often, but needs to be there, even if just for basic testing and checking over a collection.

  3. Ryan Cromwell says:

    Great example… I’m sure that’s going to be a google legacy…

  4. Dr. Search — I *do* use LookOut and I love it, but i don’t save mail forever and other folks can’t find in trapped in my PST 😉

  5. Google Legacy –

    Search = "Why do I Exist"

    Results = #1 Brad Abrams – An eample that uses List<T>.Exists…

    Yep, that’ll be a google legacy alright 😉

Skip to main content