Reputation: 853
I have this dictonary:
private Dictionary<int, ICar> _ICarsDic;
The object ICar actually contains another list of objects:
public interface ICar
{
int carId { get; set; }
string carName { get; set; }
List<IBrandsDetails> brandsDetails { get; set; }
}
I would like to write a function that returns me in a single list all the brandsDetails in all my _ICarsDic
values.
I am sure LINQ does that (don't want to write an ugly loop) but I'm new to this so would appreciate your help. Thanks!
Upvotes: 0
Views: 95
Reputation: 2696
You can write the linq as
var listOfObjects = _ICarsDic.SelectMany(t => t.Value.brandsDetails).ToList();
Upvotes: 0
Reputation: 103780
var brandDetails = _ICarsDic.Values.SelectMany(c => c.brandsDetails);
Upvotes: 1
Reputation: 223432
List<IBrandsDetails> list = _ICarsDic.SelectMany(r => r.Value.brandsDetails)
.ToList();
Upvotes: 3