static void Main(string[] args) { int[] array = new int[] { 102, 12, 23, 412, 22, 14, 45, 65, 33 }; var obj = from item in array orderby item ascending group item by item / 100; //var obj = array.Where(item => item > 100); /* foreach (var item in obj) { Console.WriteLine(item.ToString()); } */ return; }
无聊随便写Linq玩,突然发现这个问题,请看上面这段代码,理想状态下,obj结果应该是:
{0:[12,14,22,23,33,45,65]
1:[102]
4:[412]}
实际结果(请用监视查看,打印不出来的):
{0:[12,14,22,23,33,45,65,0]
1:[102]
4:[412]}
也就是说0分组最后多个0,但是这个0不在原数组array中定义,它是怎么出现的?
后来修改数组int[] array = new int[] { 102, 12, 23, 412, 22,111,156, 14, 45, 65, 33,88 };
public static void Main(string[] args) { int[] array = new int[] { 102, 12, 23, 412, 22,111,156, 14, 45, 65, 33,88 }; var obj = from item in array orderby item ascending group item by item / 100; /* foreach (var item in obj) { foreach (var t in item) { Console.Write(t + "\t"); } Console.WriteLine(); } */ return; }
这次测试结果是(请用监视查看,打印不出来的):
{0:[12,14,22,23,33,45,65,88]
1:[102,111,156,0]
4:[412]}
于是,猜测 Linq 查询结果 可能遵循 2 º,2¹,2 ²,......增长计算
时间: 2024-10-12 16:01:51