ToLookup with multiple keys

前端 未结 3 1789
囚心锁ツ
囚心锁ツ 2021-02-07 07:37

Is there a way to require multiple keys for the .ToLookup function provided by LINQ?

I will admit that this seems non-intuitive at first, and I\'m expecting

3条回答
  •  长情又很酷
    2021-02-07 08:21

    I would use Tuples for this sort of thing:

    var lookup = set.ToLookup(x => Tuple.Create(x.StringProp, x.IntProp));
    MyClass c = lookup[Tuple.Create("a", 1)].First();
    IEnumerable list = lookup[Tuple.Create("c", 4)];
    

提交回复
热议问题