小编Ede*_*den的帖子

有没有更好的方法来分组和获取每个散列角色键的客户名称?

我想知道是否还有其他方法可以编写这么长的 Linq 代码?我所需要的只是角色的散列键和其客户名称的集合。

List<Customer> customers = await GetCustomers();
Dictionary<int, IEnumerable<string>> customersDict = 
    customers.GroupBy(x => x.RoleId).ToDictionary(x => x.Key, x => x.Select(v => v.Name));
Run Code Online (Sandbox Code Playgroud)

c# linq

4
推荐指数
1
解决办法
108
查看次数

标签 统计

c# ×1

linq ×1