I have a List<Dictionary<String, String>> dictionaries. Each dictionary will contain the following keys – WAP, SystemCode and SubSystemCode. A System belongs to a WAP, and a Subsystem belongs to a System. An example of the data you might see is this:
WAP | System | Subsystem
-------------------------
01 | 01 | 01
01 | 02 | 02
02 | 01 | 01
02 | 01 | 02
02 | 03 | 02
03 | 02 | 01
I essentially want to get the following:
-
A distinct list of all WAP codes.
I think that
var waps = dictionaries.Select(d => d["WAP"]).Distinct();should work for this. -
A distinct list of all System codes for each WAP code.
The following should work:
var dictionaryGroups = dictionaries.GroupBy(d => d["WAP"]); foreach (var dictionaryGroup in dictionaryGroups ) { var wapNo = dictionaryGroup.Key; var systemCodes = dictionaryGroup.Select(d => d["SystemCode"]).Distinct(); ... } -
A distinct list of all Subsystem codes for each System code for each WAP code.
Unsure about this one.
Can someone help me out with the last one? And feel free to let me know if there is a better way to do the first two as well.
1 Answer