我有一个这样的 DTO:
public class OrderDraft
{
public string FTPUser { get; set; }
public string AccountRef { get; set; }
public string SupplyFromWarehouse { get; set; }
public string UsePriceband { get; set; }
public string DocumentDate { get; set; }
public string DateRequested { get; set; }
public string DatePromised { get; set; }
public string CustomerDocumentNo { get; set; }
public List<Line> Lines { get; set; }
public Address DeliveryAddress { get; set; }
public string ShippingChargeCode { get; set; }
public decimal ShippingFee { get; set; }
}
我像这样创建上面的字典:
Dictionary<string, OrderDraft> multiOrders
= new Dictionary<string, OrderDraft>();
现在我想返回一个 List<OrderDraft>
从上面multiOrders
字典。为此,我尝试了以下方法:
-
return multiOrders.SelectMany(s => s.Value);
-
return multiOrders.SelectMany(s => s.Value).ToList<OrderDraft>;
我收到以下错误:
Error 2 The type arguments for method 'System.Linq.Enumerable.SelectMany(System.Collections.Generic.IEnumerable, System.Func>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
知道如何检索 List<T>
来自 Dictionary<String, T>
的所有值?
最佳答案
怎么样:
multiOrders.Values.ToList()
关于c# - 选择要从字典中列出的所有对象值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23490197/