Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6749167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:39:27+00:00 2026-05-26T12:39:27+00:00

I am trying to find a linq query so I can write it in

  • 0

I am trying to find a linq query so I can write it in an if statement.

Pseudo code:

IDList is a list of ints List< int >

if (IDList.Contains (Object.Id)) Do something

but I can’t seem to work out what need.

In none-linq this works:

  foreach(int id in IDList )
     {
        if (id == Object.Id)
            break;
     }

but I want it as one line if possible.

I first tried this:

IDList.Contains(Object.Id);

but this throws a compile error

I’m wondering should it be one of these two?

  IDList.Any(id => id == Object.Id)

or

IDList.Exists(id => id == Object.Id);

I don’t completely understand how the lambdas and things work or the difference between andy and exists so I’m not sure if I’m along the wrong line?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:39:28+00:00Added an answer on May 26, 2026 at 12:39 pm

    You can simply do this:

    if (MyList.Any(c => c.Id == MyObject.Id)) { }
    

    Assuming that MyList is an IEnumerable<T> (or anything that derives from IEnumerable<T>) where T is an object that has a property named Id of the same type of the property Id on the MyObject instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find the best way to build a dynamic linq query
I' trying to use a Linq query to find and set the selected value
I'm trying to write a LINQ query to count number of ocurrences of a
I'm a bit stuck on the following linq query. I'm trying to find all
I am trying to find the corerct LINQ to SQL query operator and predicate
i am trying to write a linq query that doesn't fire a million child
For db4o, I'm trying to find the LINQ code that generates the following SODA:
I'm trying to find a way to implement a Linq-to-Entities compiled query of the
I'm trying to perform a simple Linq find first query on a typed DataTable,
Writing my first Linq application, and I'm trying to find the best way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.