我有一个函数返回以下类的IEnumerable
public class User
{
public string UserName { get; set; }
public IList<string> MemberOf { get; set; }
}
如何将IEnumerable转换为LookUp
键将是用户名,值是memberOf列表
答案 0 :(得分:3)
IEnumerable<User> seq = ...;
ILookup<string, IList<string>> lookup = seq.ToLookup(u => u.UserName, u => u.MemberOf);