2
Linq를 통해 중첩 된 그룹을 만들었습니다. 저는 학생의 이름의 0 번째 요소를 기준으로 첫 그룹을 만들었습니다. 두 번째 그룹은 학생 이름을 기준으로합니다. 외부 그룹 즉 'h'또는 'a'의 키를 가져올 수 없습니다. 도와주세요.Linq의 외부 그룹 키를 가져올 수 없습니다.
코드 :
이List<student> li = new List<practice.student>()
{
new student(){name="harry",marks=50},
new student(){name="harry",marks=60},
new student(){name="hermione",marks=50},
new student(){name="hermione",marks=60},
new student(){name="ajax",marks=60},
new student(){name="ajax",marks=70},
new student(){name="abby",marks=60},
new student(){name="abby",marks=70}
};
var query1 = li.GroupBy(t => t.name[0]).Select(t => t.GroupBy(s => s.name));
foreach (var item in query1)
{
Console.WriteLine(item.Select(t=>t.Key));
foreach (var item1 in item)
{
Console.WriteLine("Key:"+item1.Key);
foreach (var item2 in item1)
{
Console.WriteLine(item2.name+","+item2.marks);
}
Console.WriteLine();
}
Console.WriteLine();
}
출력 :
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Linq.IGrouping`2[S
ystem.String,practice.student],System.String]
Key:harry
harry,50
harry,60
Key:hermione
hermione,50
hermione,60
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Linq.IGrouping`2[S
ystem.String,practice.student],System.String]
Key:ajax
ajax,60
ajax,70
Key:abby
abby,60
abby,70
덕분에 남자 .... 그건 정말 도움이되었다 – Ajay