I have a sample object with some properties
public class MyObject
{
public string Foo { get; set; }
public string Bar { get; set; }
}
I used the GroupBy
Linq method on a collection and now have a IEnumerable<IGrouping<string, MyObject>>
. I want to map each group to be of type IGrouping<string, string>
by picking myObject.Foo + myObject.Bar
from the object class. So the final result would be IEnumerable<IGrouping<string, string>>
.
I tried to start with a Select
IEnumerable<IGrouping<string, MyObject>> oldCollection = null;
IEnumerable<IGrouping<string, string>> newCollection = oldCollection
.Select(oldGroup =>
{
IGrouping<string, string> newGroup = null;
// pick the key from the oldGroup via oldGroup.Key
// map the values from oldGroup to strings, sample code:
// newGroup.Values = oldGroup.Select(myObject => myObject.Foo + myObject.Bar);
return newGroup;
});
how can I map oldGroup
to newGroup
in that statement?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…