我想知道是否还有其他方法可以编写这么长的 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)