Let's say I have a List<NameValuePair>
, where NameValuePair is a simple object that has a Name property and a Value property, both strings.
The list is populated with values like this:
name = "name1", value = "value1"
name = "name1", value = "value2"
name = "name2", value = "value3"
name = "name3", value = "value4"
Note that there are two instances of the "name1" key. There can be any number of keys (since this is a List).
I want to turn this List into a new list, which has just unique keys, and groups any values with the same key name as an array/list of that key.
So the above should become:
name = "name1", value = "value1", "value2" // value is a string array or list
name = "name2", value = "value3"
name = "name3", value = "value4"
What is the easiest way to accomplish this?