2015-11-01 193 views
1

試圖將列表屬性轉換爲字符串,任何想法?轉換列表爲單個字符串

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

你的意思是你想* *連載您的列表? – kskyriacou

回答

6

您可以使用string.JoinSelect的結果組合成一個string

string messages = string.Join(", ", logs.Select(o => o.FormattedMessage)); 
相關問題