My question: 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); } }
I believe you are familiar with this LINQ, But I suddenly cannot understand it :)
Here, there is a digit in the where condition. I understand it as a value in digits (I do not know if it is true or not) L
So this index (theoretically the current position)
But I cannot understand where these parameters come from.
========================================================== ==================================
No one cares about me after posting the post. Haha, it's estimated that I 've been playing on May 1, so I 'd better be self-reliant.
After searching for half a day, I couldn't find a result. When the where statement was stopped, I gave a prompt with a glance, and found that the method was heavy-loaded. I checked it to the next one and understood it :)
The basic knowledge is not solid enough. The following is a detailed explanation of Microsoft:
Enumerable. Where <tsource> method (ienumerable <tsource>, func <tsource, int32, Boolean>)
Public static ienumerable <tsource> where <tsource> (
This ienumerable <tsource> source,
Func <tsource, Int, bool> Predicate
)
Type parameter
Tsource
The type of the element in source.
Parameters
Source
Type: system. Collections. Generic. ienumerable <tsource>
Ienumerable <t>.
Predicate
Type: system. func <tsource, int32, Boolean>
A function is used to test whether each source element meets the condition. The second parameter of the function indicates the index of the source element.
Return Value
Type: system. Collections. Generic. ienumerable <tsource>
An ienumerable <t> that contains elements that meet the conditions in the input sequence.
Generation of parameters: "type: system. func <tsource, int32, Boolean> is used to test whether each source element meets the conditions. The second parameter of this function indicates the index of the source element. ", The world is quiet!
Summary: Microsoft wants to reduce programming complexity, but the things to be written have increased :)
I am more and more fond of this fast-moving little fat cat.