在这个例子中:
什么是纯C#等效代码?我遇到了这个问题...
public void Linq40()
{
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var numberGroups =
from n in numbers
group n by n % 5 into g
select new { Remainder = g.Key, Numbers = g };
foreach (var g in numberGroups)
{
Console.WriteLine("Numbers with a remainder of {0} when divided by 5:",
g.Remainder);
foreach (var n in g.Numbers)
{
Console.WriteLine(n);
}
}
}
什么是纯C#等效代码?我遇到了这个问题...
var numberGroups = numbers.GroupBy(n => n % 5)...
但是into
子句有点神秘,我无法弄清楚如何从Select
中获取Key
。