小编典典

Linq选择列表中存在的对象(A,B,C)

all

我有一个清单orders
我想orders根据一组订单状态进行选择。

所以本质上select orders where order.StatusCode in ("A", "B", "C")

// Filter the orders based on the order status
var filteredOrders = from order in orders.Order
                     where order.StatusCode.????????("A", "B", "C")
                     select order;

阅读 55

收藏
2022-06-29

共1个答案

小编典典

您的状态代码也是一个集合,因此请使用Contains

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

或在查询语法中:

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