How to compare nullable int with list<int>?

var selectId = array.Where(x => x.Id != null);

selectId.Where(x => x.Id == settings.PersonIds);

Id is a nullable int and settings.PersonIds is a list of int.

How do i compare and check if the id is the same as settings.PersonIds?

Edit* i am trying to see if the list of int (settings.PersonIds) contains the int (Id)

>Solution :

Use Contains

array.Where(x => x.Id.HasValue && settings.PersonIds.Contains(x.Id.Value));

Leave a Reply