var list = Table
.GroupBy(t => t.GroupId, (key, g) => new {key, g})
.Select(t => new Transaction
{
Date = t.g.First().DateCreate,
Reference = $"{t.g.First().AccounttName} {t.g.Select(z => z.DocumentNo)}",
TotalAmount = t.g.Sum(x => x.y.Amount.Value),
})
当使用 linQ 分组时,我知道如何使用 First() 获取单个值,如何使用 Sum() 求和,但是我应该怎么做才能连接字符串值?
在我的示例中,如何合并所有 DocumentNo?
最佳答案
使用string.Join
:
Reference = $"{t.g.First().AccounttName} {string.Join(",",t.g.Select(z => z.DocumentNo))}"
关于c# - 如何在 LinQ 组中连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44538355/