我该如何进行此转换?是否可以使用一些简单的LINQ查询?
答案 0 :(得分:1)
如果V是查询中未涉及的其他类型,则可以使用let关键字创建实例,然后对其进行分组...
from x in Y
let v = new V(x.Whatever)
group v by v.Whatever into vGroup
select vGroup
答案 1 :(得分:0)
假设V继承自U并且您希望将每个U转换为V:
IEnumerable<IGrouping<string, U>> groupingsOfU =
from u in listOfU
group u by u.Foo;
IEnumerable<IGrouping<string, V>> groupingsOfV =
from g in groupingsOfU
from u in g
group (V)u by g.Key;