Reputation: 3359
Need linq expression to get list of distinct Iternary.Name from all dictionary entry's value's Iternary.Name.
Objects are below format:
public class IternaryInfo
{
public string Name { get; set; }
public Iternary[] IternaryList { get; set; }
}
public class Iternary
{
public string Name { get; set; }
}
Dictionary<String, IternaryInfo> dictionary = new Dictionary<String, IternaryInfo>();
Is this poss in one expression or have to go with looping.
tried - dictionary.Select(x=>x.Value.IternaryList).ToList()
, but not sure, how to pick -Name field from Iternary.
Upvotes: 1
Views: 70
Reputation: 43886
You need to:
SelectMany
and thenIternary
s to their Name
s using Select
and thenuse Distinct
to get only distinct values
var result = dictionary.Values
.SelectMany(v => v.IternaryList)
.Select(i => i.Name)
.Distinct().ToList();
Upvotes: 7