我将查询语法选择示例从 MSDN 转换为 Lambda。它有效,我自己写的,但我无法理解下面的评论行。我的意思是,我从numbers数组中选择,但它工作正常,而不是数字显示等效字符串。它如何匹配两个数组?
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
string[] strings = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine" };
//Confusing line: **How would we represent this line below in plain english?**
var result = numbers.Select(d => strings[d]);
foreach (var d in result)
{
Console.WriteLine(d);
}
输出:
five
four
one
..rest of numbers follow
查询语法中的原始 MSDN 代码:
var result=
from n in numbers
select strings[n];
foreach (var s in strings)
{
Console.WriteLine(s);
}
也许解释这样的事情有点棘手,但我希望有人说得对,所以这很有意义:)
谢谢