将List转换为单个字符串

时间:2015-11-01 13:37:22

标签: c# linq

尝试将List属性转换为字符串,任何想法?

public class ContactLog
{
     public string To { get; set; }
     public string Message { get; set; }

     public string FormattedMessage
     {
         get { return To+ ',' + Message; }
     }
 }

public void SendBatch(List<ContactLog> logs)
{
    //Problem Line
    string messages = CreateBulkMessage(logs.Select(o => o.FormattedMessage));
}
public string CreateBulkMessage(string message)
{
    //Do Stuff
}

1 个答案:

答案 0 :(得分:6)

您可以使用string.JoinSelect的结果合并为一个string

string messages = string.Join(", ", logs.Select(o => o.FormattedMessage));