I have a collection that contains a list of complex objects, “SubCategory”. SubCategory contains “Category”.
I can iterate through my collection and see all object, and drill down through to Category.
How can I, using Linq, extract a distinct list of Categories?
I initially tried this in a foreach loop:
if (!categoryList.Contains(baseline.ContentCategory)
{
categoryList.Add(baseline.ContentCategory);
}
But that just does not work, and I think a Linq solution would be more elegant.
Thanks.
subCategoryList.Select(s => s.Category).Distinct()