Linq To Object查询问题

我的问题:http://topic.csdn.net/u/20110430/23/9ccd7f75-4d4b-49b1-9a76-f8c985b607dd.html?60564

===================================================================

public static void Linq5()
  {
         string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

          var shortDigits = digits.Where((digit, index) => digit.Length < index);

          Console.WriteLine("Short digits:");
          foreach (var d in shortDigits)
          {
               Console.WriteLine("The word {0} is shorter than its value.", d);
           }
  }

相信各位对这个linq都很熟悉,我现在突然搞不明白了:)
其中where条件中有一个digit,我理解为是digits中的一个值(不知道对不对)l
那么这个index(理论上应该是当前位置)

可我就是弄不明白了这些参数是从那里来的,呵呵,钻牛角尖里去了,请各位高手帮忙解释下

=====================================================================

发完贴看没人理我,呵呵,估计都过五一去玩了,还是自力更生吧。

找了半天没找到个结果,在where语句停下时眇了一眼提示,发现方法是重载的,点到下一个一看,明白了:)

还是自已的基础知识不够扎实啊,下面的微软的具体解释:

Enumerable.Where<TSource> 方法 (IEnumerable<TSource>, Func<TSource, Int32, Boolean>)
public static IEnumerable<TSource> Where<TSource>(
    this IEnumerable<TSource> source,
    Func<TSource, int, bool> predicate
)

类型参数
TSource
source 中的元素的类型。

参数
source
类型:System.Collections.Generic.IEnumerable<TSource>
要筛选的 IEnumerable<T>。

predicate
类型:System.Func<TSource, Int32, Boolean>
用于测试每个源元素是否满足条件的函数;该函数的第二个参数表示源元素的索引。

返回值
类型:System.Collections.Generic.IEnumerable<TSource>
一个 IEnumerable<T>,包含输入序列中满足条件的元素。


各参数的产生:“类型:System.Func<TSource, Int32, Boolean>用于测试每个源元素是否满足条件的函数;该函数的第二个参数表示源元素的索引。”,世界安静了!

总结:微软希望使我们减少编程的复杂度,但要记下来的东西却增加了:)

越来越喜欢这个狂奔中的小肥猫了,再专门贴一个

原文地址:https://www.cnblogs.com/forrestsun/p/2042614.html