I have a List of List of KeyValuePairs which I would like to bring to a standard form and further export it as a table. To do this I need to get all unique Keys present in the list. How can I get the unique keys with LINQ?
My source data has this form:
var sourceData = new List<List<KeyValuePair<string, string>>>();
...
var uniqueKeyNames = sourceData.SomeLinqCodeHere....
Many thanks
It sounds like you just need a combination of
SelectMany
,Select
andDistinct
:Note that if you want to iterate over
allKeys
more than once, you probably want to materialize the query, e.g. by callingToList
at the end: