At times when you want to check for an Item inside a List
List.Exists(Predicate match)
List
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"; }));
Published 30 September 04 08:00 by BradA
http://blogs.msdn.com/brada/archive/2004/09/30/236460.aspx
In my case I had to check against an object and not the string.
this will work, SourceFieldID is of type string.
bool itemExists = _criteriaItems.Items.Exists(delegate(CriteriaItem ci) { return ci.SourceFieldId == item.SourceFieldId; });
but this wont work, it will always return false.
bool itemExists = _criteriaItems.Items.Exists(delegate(CriteriaItem ci) { return ci == item; });
happy coding!!