重新_concat
您问题的方面,使用:
static class EnumerableExtensions
{
public static String AsJoined( this IEnumerable<String> enumerable )
{
return AsJoined( enumerable, "," );
}
public static String AsJoined( this IEnumerable<String> enumerable, String separator )
{
return String.Join( separator, enumerable.ToArray() );
}
}
bruno conde 和 Jon Skeet 的答案中的输出 foreach 可以变成:
Console.WriteLine( "User:\tHobbies");
foreach ( var group in groupedUsers )
Console.WriteLine( "{0}:\t{1}", group.Key, group.Select( g => g.Hobby ).AsJoined( ", " ) );
...您将获得您要求的精确结果输出格式(是的,我知道其他人已经解决了您的问题,但很难抗拒!)