<p>I have a <code>List&lt;int&gt;</code> and a <code>List&lt;customObject&gt;</code>. The customObject class has an ID property. How can I get a <code>List&lt;customObject&gt;</code> containing only the objects where the ID property is in the <code>List&lt;int&gt;</code> using LINQ?</p>

<p><strong>Edit</strong>: I accepted Konrads answer because it is easier/more intuitive to read.</p>

[{'answer_id': 37807, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 3, 'selected': False, 'text': '<p>Untested, but it\'ll be something like this:</p>\n\n<pre><code>var matches = from o in objList \n                  join i in intList on o.ID equals i\n                  select o;\n</code></pre>\n\n<p>@Konrad just tested it, and it does work - I just had a typo where I\'d written "i.ID" rather than "i".</p>\n'}, {'answer_id': 37810, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 5, 'selected': True, 'text': '<pre><code>var result = from o in objList where intList.Contains(o.ID) select o\n</code></pre>\n'}, {'answer_id': 158915, 'author': 'Lucas', 'author_id': 24231, 'author_profile': 'https://Stackoverflow.com/users/24231', 'pm_score': 2, 'selected': False, 'text': '<p>Just for completeness (and maybe it\'s easier to read?), using a "where" similar to Matt\'s "join":</p>\n\n<pre><code>var matches = from o in customObjectList\n              from i in intList\n              where o.ID == i\n              select o;\n</code></pre>\n'}, {'answer_id': 1491976, 'author': 'Henryk', 'author_id': 18659, 'author_profile': 'https://Stackoverflow.com/users/18659', 'pm_score': 3, 'selected': False, 'text': '<p>I have had a similar problem just now and used the below solution.  If you already have the list of objects you can remove all not found in the int list, leaving just matches in objList.</p>\n\n<pre><code>objList.RemoveAll(x =&gt; !intList.Contains(x.id));\n</code></pre>\n'}, {'answer_id': 6962016, 'author': 'Diana ', 'author_id': 881256, 'author_profile': 'https://Stackoverflow.com/users/881256', 'pm_score': 0, 'selected': False, 'text': '<p>Please note that using the join instead of contains DOES NOT work when the count of items in the list exceeds 49!  You will get the error: <code>Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.</code></p>\n'}, {'answer_id': 19765766, 'author': 'Robin Winslow', 'author_id': 613540, 'author_profile': 'https://Stackoverflow.com/users/613540', 'pm_score': 4, 'selected': False, 'text': '<pre><code>using System.Linq;\n\nobjList.Where(x =&gt; intList.Contains(x.id));\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/37805', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2257/']