Reputation: 24116
I have a DTO like this:
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; }
}
I create a dictionary of the above like this:
Dictionary<string, OrderDraft> multiOrders
= new Dictionary<string, OrderDraft>();
Now I want to return a List<OrderDraft>
from the above multiOrders
dictionary. To achieve this, I tried the following:
return multiOrders.SelectMany(s => s.Value);
return multiOrders.SelectMany(s => s.Value).ToList<OrderDraft>;
I am getting the following error:
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.
Any idea how to retrieve a List<T>
of all values from a Dictionary<String, T>
?
Upvotes: 5
Views: 10232
Reputation: 13297
@nvoigt solution is dead on, but you could also just deal with the warning by declaring type parameters explicitly:
return multiOrders.SelectMany<OrderDraft,OrderDraft>(s => s.Value).ToList<OrderDraft>;
Upvotes: 0