SelectMany의 파생 된 LINQ 쿼리를 만들려고합니다. 나는 List<List<object>>()
,로 결과를 싶습니다속성 합계로 LINQ 그룹
new {
{ Text = "Hello", Width = 2 },
{ Text = "Something else", Width = 1 },
{ Text = "Another", Width = 1 },
{ Text = "Extra-wide", Width = 3 },
{ Text = "Random", Width = 1 }
}
: 나는 N 항목이
이List<List<object>> = new {
// first "row"
{
{ Text = "Hello", Width = 2 },
{ Text = "Something else", Width = 1 },
{ Text = "Another", Width = 1 }
},
// second "row"
{
{ Text = "Extra-wide", Width = 3 },
{ Text = "Random", Width = 1 }
}
}
그래서 항목 "행"으로 분류됩니다 경우 내부 목록에서 합계 (폭) 숫자보다 작거나 같습니다 (maxWidth - 내 인스턴스에서 4). 그것은 다소 GroupBy의 파생물이지만 GroupBy는 배열의 초기 값에 의존합니다.
모든 아이디어를 얻을 수 있습니다.
좋지만 더 많거나 적습니다 (필자는 훨씬 더 우아하고 융통성있게 동의해야합니다!) 아래 답변을 구현하십시오. – derpirscher
@derpirscher 슬프게도 우아함이이 라운드에서 우승합니다. –
물론 @codegecko! 나는 너무 upvoted;) – derpirscher