Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ check if int? is in List<Int> C# [duplicate]

Tags:

c#

list

int

linq

I have object with ID = 5, ID = 6 and List 1,5. Since list has 5 i need to have object with ID = 5 as a result, but if my list has 5 and 6 i need to have both objects as a result. Hope i'm clear enough.

So something like this:

result = result.Where(r=>r.ID ***IS IN LIST<int>***).OrderBy(r=>r.ID);

Any help is appreciated.

like image 844
azza idz Avatar asked Dec 05 '22 20:12

azza idz


1 Answers

result = result.Where(r=>listOfId.Contains(r.ID)).OrderBy(r=>r.ID);
like image 189
deramko Avatar answered Dec 08 '22 11:12

deramko