c# - 选择要从字典中列出的所有对象值

标签 c# linq dictionary

我有一个这样的 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/

相关文章:

c# - 在 Dictionary<DateTime, double> 中查找最接近的 DateTime 键

c# - LINQ 内连接与左连接

python - 将 NoneType 分配给 Dict

c# - 当键不是简单的原始类型时使用 ContainsKey()

javascript - 如何在 javascript 中迭代 'fetch' 返回的结果?

c# - ASP.NET Core 自定义验证属性未触发

c# - 为什么 "as T"会出错,但使用 (T) 进行转换不会出错?

c# - 选择对象集合的列/字段并导出为 List<>

c# - 对 Viewmodel 进行单元测试

c# - 如何从接口(interface)返回派生程度更高的类型?