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();
- .Select(grp=> new
- {
- Parent = grp.Key,
- ConsecutiveNodes = grp.Select((n, i)=> new
- {
- Index = i+1,
- Node = n
- }),
- Count = grp.Count()
- })
Laxmidhar SahooPosted Mar 2, 2018, 6:32 AM