Linq List contains specific values.

Posted by Raffaeu on Stack Overflow See other posts from Stack Overflow or by Raffaeu
Published on 2011-01-06T15:48:14Z Indexed on 2011/01/06 15:53 UTC
Read the original article Hit count: 147

Filed under:

I need to know if the List I am working with contains only some specific values.

var list = new List<string> { "First", "Second", "Third" };

If I want to know if the List contain at least one item with the value "First" I use the Any keyword:

var result = list.Any(l => l == "First");

But how I can write a Linq expression that will return true/false only if the List contains "First" and "Second" values?

© Stack Overflow or respective owner

Related posts about LINQ