static void Main (string[] args)
{
var beatles = (new[] {new {id=1, Inst = "Guitar", Name= "John"},
new {i d=2, inst = "Guitar", Name= "George"},
new {id=3, Inst = "Guitar", Name= "Paul"},
new {id=4, Inst = "Drums" , name= "Ringo"},
new {id=5, Inst = "Drums", Name= "Pete"}
);
Method 1
//Method 2
foreach (var i in O)
{
Console.WriteLine ("{0} {1} {2}", I.inst, I.name, i.rn);
}
Console.ReadLine ();
}
Method 1:
var o = Beatles. By (M => m.id). ToList (). GroupBy (x => x.inst)
. SelectMany (t => t.select ((b, i) => new {b, i})). Select (M => m.b);
Method 2:
var o = Beatles. By (x => x.id). GroupBy (x => x.inst)
. Select (g => new {g, Count = G.count ()})
. SelectMany (t => t.g.select (b => b). Zip (Enumerable.range (1, T.count), (J, i) => new {j.inst, j.name, RN = i}));
Results:
Guitar John 1
guitar George 2
guitar Paul 3
drums Ringo 1