How to check if an element exists within a list?

3

I need to check if there is a state in my list ... I am passing a parameter (a status code) and the method will see in the list if that state exists ... something like this in C #:

if (listState.Contains(s.nIDState) == estado)
{
    return true;
}

Does anyone have an idea how to do it?

    
asked by anonymous 17.09.2014 / 23:34

2 answers

5

If I understand correctly:

return listState.Any(l => l.nIDState == estado);

Any is an extension of% with%. It checks if there is at least one item in the list that is equal to Enumerable , returning estado , or true otherwise.

    
17.09.2014 / 23:38
0

So I understand you want to know if there is an element in a list in a column. Do this:

return listState.FindAll(l => l.nIDState == "estado");

FindAll looks for what exists within a given column.

It is good to find certain item returned from a database query ....

    
18.09.2014 / 19:44