Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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>();
l.Add("Red");
l.Add("Green");
l.Add("Blue");
l.Add("Purple");
//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
- Anonymous
September 30, 2004
You really should start using Lookout.:-) - Anonymous
September 30, 2004
Equivalent FindAll and ConvertAll examples:
http://weblogs.asp.net/justin_rogers/archive/2004/04/30/123780.aspx
A ForEach sample as well:
http://weblogs.asp.net/justin_rogers/archive/2004/04/30/123807.aspx
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. - Anonymous
September 30, 2004
Great example... I'm sure that's going to be a google legacy... - Anonymous
September 30, 2004
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 ;-) - Anonymous
October 01, 2004
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 ;-) - Anonymous
March 05, 2006
PingBack from http://daily.feature42.com/PermaLink,guid,7128454b-4f6b-4038-9c5b-594567a5bc17.aspx