c# - SkipWhileIterator method implementation understanding -
I'm reading that CLR can take it, for example, what is happening when implementing the SkipWhile method. :
IList & lt; String & gt; Numbers = New list & lt; String & gt; () {"one two three four five"}; Var results = numbers While skip (number = & gt; number = thumb == 3); result. Toolist () (Number => console WrightLine (number)) for;
CLR will do these steps:
The C # compiler uses an anonymous method ( to be a method
) in compile time. As a definition of & lt; main & gt; B__1
number = & gt; number. length == 3 & lt; CLR
method will instal an example of left time
Main & gt; Using the b__1 multicast delegate
. Using the CLR original list, give an example of the SkipWhileIterator
iterator, and & lt; Main & gt; B__1
Due to suspended execution, SkipWhileIterator
CLR
does not call toList
call or ForEach
method To repeat through the uses, CLR runs the toList
method to SkipWhileIterator
on SkipWhileIterator Inside
, under the CLR
original list, execute uniform on each of the items and if the information is incorrect, then S KipWhileIterator
returns the code as the result of the SkipWhile
method;
So far, everything is fine.
However, I have seen the implementation of SkipWhileIterator
.
Fixed IEnumerable & lt; TSource & gt; SkipWhileIterator & lt; TSource & gt; (IEnumerable & lt; TSource & gt; source, functic & lt; TSource, bool & gt; predicate) {bool yielding = false; FORECA (tsos element in source) {if (! Yield and !; ADYT) yield = true; If yield (returns) yield returns element; }}
But, is not it wrong? In my opinion the second statement should be like that:
if (yield) {yield = false; Yield returns element};
The value of the prevailing
should be set to false on the other side, , otherwise if the value is not found within the statement then the value is true .
Thank you.
Once leave
gets a value that does not match the ingenuity The account stops seeing it and just returns the rest of the sequence yield
starts false, so that the elements will not return, and it will be set to the right on the non-match first. After this, it does not want to make the statement again in the first if
because it already knows that after that the elements are going to return.
Comments
Post a Comment