0

我想将以下查询绑定到 DataGridview。我该怎么办?

int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var numberGroups =
                 from num in numbers
                 group num by num % 5 into numGroup
                 select new { Remainder = numGroup.Key, Numbers = numGroup };
4

1 回答 1

1

您希望它如何在 DGV 中表示,因为 Numbers 可能包含多个项目,这将如何进入 DGV 行?

或者,这应该工作:

var numberGroups = from num in numbers
                   group num by num % 5 into numGroup
                   select new { Remainder = numGroup.Key, Count = numGroup.Count() };

yourGridView.DataSource = numberGroups.ToList();
yourGridView.DataBind();  //don't use if WinForm DGV
于 2012-08-31T20:08:57.990 回答