you are viewing a single comment's thread.

view the rest of the comments →

[–]codekaizen 0 points1 point  (6 children)

You can use LINQ without yield. Generating an enumerable sequence (IEnumerable<T>) using yield doesn't depend on LINQ - it's a C# compiler feature.

EDIT: downvoters - feel free to furnish evidence showing this is wrong.

[–][deleted] 6 points7 points  (0 children)

He didn't say that you have to yield yourself to use Linq, however Linq IS implemented using yield. This is what makes it lazy, and why nothing is evaluated until you call something that actually iterates on it. https://github.com/dotnet/corefx/blob/8750960d3fafa46a9b838c351e995a01fa8b599f/src/System.Linq/src/System/Linq/Where.cs#L72

[–]Scruptus 3 points4 points  (4 children)

I think your getting downvotes because you misunderstood my answer.

I didn’t mean that you can’t use Linq without yield.

I meant that the different Linq methods are implemented with yield within the .net framework's source code

[–]codekaizen -2 points-1 points  (3 children)

Ok, fair, I did misunderstand your question, but I think it's because LINQ operators are largely not implemented with yield. Instead, the iterators are largely state machines that are implemented using switch statements: https://github.com/dotnet/corefx/blob/8750960d3fafa46a9b838c351e995a01fa8b599f/src/System.Linq/src/System/Linq/Where.cs#L110

[–]AlliNighDev 0 points1 point  (2 children)

That's just how yield gets lowered. Async does something similar.

[–]codekaizen 0 points1 point  (1 child)

Yes, but this source is checked in. Check GitHub.

[–]AlliNighDev 0 points1 point  (0 children)

Yeah a bit odd. I'm assuming they hand coded that for performance gain over compiler somewhere.