0

i have this class:

   class Article
    {
            public int Id { get; set; }
            public string Name { get; set; }
    }


    List<Article> arts = new List<Article>();

I have a list of objects. These objects have two variables ID, Name. I need to check if in this list there is an article with name = "Cheese". How can I do to make this search returns a Boolean value? Any help would be great! Thanks!

2 Answers 2

4
bool hasCheese = arts.Any(a => a.Name == "Cheese");
Sign up to request clarification or add additional context in comments.

Comments

1

Simple: -

bool contains = arts.Any(x => x.Name == "Cheese");

Any will return a bool indicating whether or not the list contains Cheese

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.