[Solved] how to prepare the comma separated strings with guid in this scenario? [closed]


You can do it with GroupBy. Assume that your pairs are stored in a class like this:

class Pair {
    public Guid Id {get;set;}
    public string Val {get;set;}
}

You can produce the desired result as follows:

foreach (var g in data.GroupBy(p=>Id)) {
    Console.WriteLine(                  // Change this to the desired destination
        "{0} => {1}"
    ,   g.Key                                     // Produces GUID
    ,   string.Join(",", g => g.Select(p=>p.Val)) // Makes a comma-separated list
    );
}

1

solved how to prepare the comma separated strings with guid in this scenario? [closed]