return 个元素从数组的开头开始,直到命中一个小于其在数组中的位置的数字?
return elements starting from the beginning of the array until a number is hit that is less than its position in the array?
以下代码产生错误
Cannot convert lambda expression to type 'int' because it is not a delegate type.
我的代码:
public void test() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var firstSmallNumbers = numbers.Take((n, index) => n >= index);
Console.WriteLine("First numbers not less than their position:");
foreach (var n in firstSmallNumbers)
{
Console.WriteLine(n);
}
}
问题
如何停止产生错误?
请使用 TakeWhile 而不是仅 Take
以下代码产生错误
Cannot convert lambda expression to type 'int' because it is not a delegate type.
我的代码:
public void test() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var firstSmallNumbers = numbers.Take((n, index) => n >= index);
Console.WriteLine("First numbers not less than their position:");
foreach (var n in firstSmallNumbers)
{
Console.WriteLine(n);
}
}
问题
如何停止产生错误?
请使用 TakeWhile 而不是仅 Take