I have a GroupBy
expression that has an anonymous type key with more than one property. I would like to store each property in a separate variable.
When I look at it in the debugger, items.key
looks like this: { Location = Halifax, Address = abc, City = abcde }
.
How would I extract the individual properties of the anonymous type into a variable? Something like var foo = items.key[Location]
?
private class ReportItem
{
public string Location { get; set; }
public string City { get; set; }
public string Address { get; set; }
public string UserName { get; set; }
public string QA { get; set; }
}
---
finalReportList.Add(new ReportItem
{
Location = location,
City = city,
Address = address,
UserName = name,
QA = qa
});
var testquery = finalReportList.GroupBy(x => new {x.Location, x.City, x.Address});
foreach (var items in testquery)
{
var location = items.Key;
}