Yes, it yield returnexecutes the continuation form. Although for many useful cases, Linq provides functional operators that allow you to combine a lazy sequence generator, so in fact in C # 3 there is no need to use yield returnso much (except for adding additional Linq extensions in yours to fill in the spaces in the library, for example Zip, Unfold) .
In the example, we multiply an integer by brute force. Essentially, the same example in C # can be performed with Linq built-in operators:
var factors = Enumerable.Range(2, 100)
.Join(Enumerable.Range(2, 100),
n => 1, n => 1, (i, j) => new { i, j })
.First(v => v.i*v.j == 481);
Console.WriteLine("Factors are " + factors.i + ", " + factors.j);
Here, the starting points are my two calls Enumerable.Range, which is built into Linq, but you can implement yourself as:
IEnumerable<int> Range(int start, int stop)
{
for (int n = start; n < stop; n++)
yield return n;
}
, n => 1, n => 1 Join. 1 Join , , .
( ):
(i, j) => new { i, j })
, , :
.First(v => v.i*v.j == 481);
First . , "", :
.First(v =>
{
Console.WriteLine("Aren't lambdas powerful things?");
return v.i*v.j == 481;
);
, , , . , , false - amb .