可以將多行連接到單個行嗎?在LINQ中將多個行連接成單個行
例如:
IEnumerable<sample> sam = new List<sample>()
{
new sample{ id = 1, name = "sample 1", list = new List<int>{1,5,6}},
new sample{ id = 2, name = "sample 2", list = new List<int>{2,9}},
new sample{ id = 3, name = "sample 3", list = new List<int>{8,3,7}},
new sample{ id = 4, name = "sample 4", list = new List<int>{3,4,8}},
new sample{ id = 5, name = "sample 5", list = new List<int>{1,5,7}},
new sample{ id = 6, name = "sample 6", list = new List<int>{6,9,7}}
};
輸出必須:
{
new sample { id = 1, name = "sample 1", list = "1,5,6" },
new sample { id = 2, name = "sample 2", list = "2,9" },
new sample { id = 3, name = "sample 3", list = "8,3,7" },
new sample { id = 4, name = "sample 4", list = "3,4,8" },
new sample { id = 5, name = "sample 5", list = "1,5,7" },
new sample { id = 6, name = "sample 6", list = "6,9,7" }
};
,從列表意味着現在新行是一個字符串。
由於'list'可以被定義爲一個'List'或一個'string',而不是兩者,否則你將無法返回'樣本',但否則這是相當微不足道的LINQ。 –
Rawling