Reputation: 2748
Below I am trying to see if the text is already contained in the list. The code always goes into the if statement.Why?
if(MyGlobals.ListOfItemsToControl.FindAll(x => x.sItemName == info.FullName ) != null)
{
...
}
Upvotes: 1
Views: 77
Reputation: 14614
if (MyGlobals.ListOfItemsToControl.Any(x => x.sItemName == info.FullName))
{
...
}
if (MyGlobals.ListOfItemsToControl.Exists(x => x.sItemName == info.FullName))
{
...
}
Upvotes: 4
Reputation: 60493
use Any instead of FindAll
if(MyGlobals.ListOfItemsToControl.Any(x => x.sItemName == info.FullName ))
FindAll
doesn't return null if value is not found, it returns an empty collection.
So you could do (but don't)
if(MyGlobals.ListOfItemsToControl.FindAll(x => x.sItemName == info.FullName ).Any())
Upvotes: 7