Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get keys from IList<IDictionary<string, object>>

Tags:

c#

linq

I have

IList<IDictionary<string, object>> 

How get without duplication keys from all of dictionaries inside this IList and put them to IList<string> using LINQ?

like image 851
SomeGenericNameto_Display Avatar asked Dec 24 '22 11:12

SomeGenericNameto_Display


1 Answers

Use SelectMany and Distinct

List<string> uniquekeys = listOfDictionaries
    .SelectMany(d => d.Keys)
    .Distinct()
    .ToList();
like image 125
Dennis Avatar answered Dec 27 '22 17:12

Dennis