【发布时间】:2009-10-02 06:59:27
【问题描述】:
我从 msdns 101 linq 示例中得到了这个 linq 示例:
public void Linq12() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var numsInPlace = numbers.Select((num, index) => new {Num = num, InPlace = (num ==
index)});
Console.WriteLine("Number: In-place?");
foreach (var n in numsInPlace) {
Console.WriteLine("{0}: {1}", n.Num, n.InPlace);
}
}
这是我的问题:
什么是 (num, index) 部分?这些可以称为 a,b 之类的名称吗?可以有多少我想要的?
编译器如何确定匿名类型将是什么类型?
=> 有什么用?
-
必须始终至少有一个参数。例如,在下面的 linq 查询中是 n 个参数或此选择与另一个不同 (Select(num,index))
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var numsPlusOne = from n in numbers select n + 1; }
【问题讨论】: