var aikazus = new[]{
new{ ID = 1, SubID = 1, Name = "aikazu11a"},
new { ID = 1, SubID = 1, Name = "aikazu11b"},
new { ID = 1, SubID = 2, Name = "aikazu12a"},
new { ID = 1, SubID = 2, Name = "aikazu12b"},
new { ID = 1, SubID = 3, Name = "aikazu13a"},
new { ID = 1, SubID = 3, Name = "aikazu13b"},
new { ID = 1, SubID = 3, Name = "aikazu13c"},
new { ID = 2, SubID = 1, Name = "aikazu21a"},
new { ID = 2, SubID = 2, Name = "aikazu22a"},
new { ID = 2, SubID = 2, Name = "aikazu22b"},
new { ID = 2, SubID = 3, Name = "aikazu23a"},
new { ID = 2, SubID = 3, Name = "aikazu23b"},
new { ID = 2, SubID = 3, Name = "aikazu23c"},
};
// IDとSubID毎にまとめて処理をしたい時はToLookupが便利。
// 複数の場合はこのようにToLookupを重ねがけしてあげる。
foreach (var ids in aikazus.ToLookup(it => it.ID)) {
foreach (var subids in ids.ToLookup(it => it.SubID)) {
Console.WriteLine("ID:" + ids.Key + " SubID:" + subids.Key + " Menbers:" + string.Join(", ", subids.Select(it => it.Name).ToArray()));
}
}