How can I do this conversion? Is it possible with some simple LINQ query?
If V is some other type not involved in the query, you can use the let keyword to create an instance and then group on it...
from x in Y
let v = new V(x.Whatever)
group v by v.Whatever into vGroup
select vGroup
Assuming that V inherits from U and you want to cast each U to a 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;
精彩评论