I want to select from List with array condition
I want to do that
var res = from r in liste where r.id1==array1 ||r.id2==arry1 select r;
the array1 and array2 are arrays contains ids
how can I do that
If you want items in list
that have an id1
contained in array1
or an id2
contained in array2
you can do this:
var res = from r in list where array1.Contains(r.id1) || array2.Contains(r.id2) select r;
EDIT: if id1
and id2
are nullable int
s:
var res = from r in list
where r.id1.HasValue && array1.Contains(r.id1.Value) ||
r.id2.HasValue && array2.Contains(r.id2.Value)
select r;
Where函数还有一个索引参数:
var res = liste.Where((r, i) => r.id1 == array1[i] || r.id2 == array1[i]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.