3

I can use the below code to group by a ID property in an array which works.

var docArray = MyArray;                                                        

var docGroup = docArray.GroupBy(x => x.ID)
    .Select(grp => new
    {
        Id = grp.Key,
        Results = grp.ToList(),
    }).ToList();

If MyArray has another array inside it which has a property say Data can some please tell me how to do the grouping based on the Data property.

class MyArray
{
    SecondArray[] arr = new SecondArray[2];
    public int ID{get;set;}   
}

class SecondArray
{
    public string Data{ get; set; }   
}

1 Answer 1

3
var query = from a in docArray
            from b in a.arr
            group new { a, b } by b.Data into g
            select new
            {
              g.Key,
              Results = g.ToList()
            };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.