尝试将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
}
答案 0 :(得分:6)
您可以使用string.Join
将Select
的结果合并为一个string
:
string messages = string.Join(", ", logs.Select(o => o.FormattedMessage));