I want to create new list of list on basis of a single list. I have a list like
public class OfficeLocator
{
public String id{ get; set; }
public string Geography{ get; set; }
public string Country{ get; set; }
public string State{ get; set; }
public string OfficeName{ get; set; }
}
I am trying to prepare an tree structured list
GeographyName="Asia",
{
Country = "China",
{
State = "Hunan",
{
{
OfficeId = "1",
OfficeName = "Office 1"
},
{
OfficeId = "2",
OfficeName = "Office 2"
}
},
State = "Hubei"
{
{
OfficeId = "3",
OfficeName = "Office 3"
}
}
},
Country = "India",
{
State = "Maharashtra",
{
{
OfficeId = "4",
OfficeName = "Office 4"
},
{
OfficeId = "5",
OfficeName = "Office 5"
}
},
State = "Punjab"
{
{
OfficeId = "6",
OfficeName = "Office 6"
}
}
},
},
GeographyName="Europe",
{
Country = "UK",
{
State = "York",
{
{
OfficeId = "7",
OfficeName = "Office 7"
},
{
OfficeId = "8",
OfficeName = "Office 8"
}
}
}
}
I tried using some group by on Geography and Country.
But I am not getting the required output.
I can use looping logic to get the result, but I want to avoid it and try something with linq.