gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:52:06 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com