I recenty stumbled upon a piece of LINQ code written below
- var cons = xdoc.Descendants("xref")
- .Where(x=>x.Attribute("rid").Value.Contains("ref"))
- .GroupBy(x=>x.Parent)
- .Select(grp=> new
- {
- Parent = grp.Key,
- ConsecutiveNodes = grp.Select((n, i)=> new
- {
- Index = i+1,
- Node = n
- }),
- Count = grp.Count()
- })
- .ToList();
Now I cannot understand the part
- .Select(grp=> new
- {
- Parent = grp.Key,
- ConsecutiveNodes = grp.Select((n, i)=> new
- {
- Index = i+1,
- Node = n
- }),
- Count = grp.Count()
- })
Can anyone break it down for me because I cannot figure it out on my own, there are a lot of new things that I haven't seen before...like an anonymous type inside and anonymous type? and what is the
grp.Select((n, i) thing? how does it work?