How to check if there is an element inside a list?

Asked

Viewed 14,235 times

4

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

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

someone has an idea how to do?

2 answers

7


If I understand correctly:

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

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

  • That’s exactly what I want...

  • 1

    Perfect is that even worked out here thank you very much !

  • 1

    I did it and it worked too, vlw !

0

From what I understand you want to know if there is an element in a list in a do column like this:

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

Findall looks for what exists inside a certain column.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.