Linq select objects in list where exists IN (A,B,C)

前端 未结 5 1780
闹比i
闹比i 2020-11-28 04:05

I have a list of orders.
I want to select orders based on a set of order statuses.

So essentially select orders where order.Statu

5条回答
  •  眼角桃花
    2020-11-28 04:38

    Your status-codes are also a collection, so use Contains:

    var allowedStatus = new[]{ "A", "B", "C" };
    var filteredOrders = orders.Order.Where(o => allowedStatus.Contains(o.StatusCode));
    

    or in query syntax:

    var filteredOrders = from order in orders.Order
                         where allowedStatus.Contains(order.StatusCode)
                         select order;
    

提交回复
热议问题