This is what I have
ID Value
1 Val1
1 Val2
3 Val3
3 Val4
4 Val5
I need
ID Value
1 Val1, Val2
3 Val3, Val4
5 Val4
I am stuck at this point:
var groups = Result.GroupBy(res => res.ID);
foreach (var group in groups)
{
foreach (var entry in group)
{
}
}
How to get the result into a new anonymous type?
Note, I also need a concrete type that can be serialized as well.
EDIT: The final solution was like
[Serializable]
public class KeyValueCSV
{
public decimal Key { get;set;}
public string CSVValues { get;set;}
}
List<KeyValueCSV> kvCSVList = new List<KeyValueCSV>();
KeyValueCSV kvCSV;
var groups = Result.GroupBy(res => res.ID);
foreach (var group in groups)
{ kvCSV = new KeyValueCSV();
foreach (var entry in group)
{
kvCSV.id = entry.id;
kv.CSVValues = enrty.Value + ", ";
}
kvCSVList.Add(kvCSV);
}
Group has everything you need
You could also do it:
**Let me know if I messed something up 😉 I have been in the world of python recently so I might have managed to mix up some sytax…