Allow C# to use anonymous iterators.
See original GitHub issueVB.net allows you to have a lambda return an iterator, it should hopefully be possible to use such functionality in c#. E.g.
Func<IEnumerable<int>> f = ()=>yield return 3;
While that’s a terrible example it hopefully can demonstrate the point.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:24 (8 by maintainers)
Top Results From Across the Web
In C#, why can't an anonymous method contain a yield ...
If anonymous methods are allowed to contain iterator blocks, then both those assumptions go out the window. You can have an iterator block ......
Read more >C#: Coding With Anonymous Methods, Iterators, And ...
Iterating over collections; Spanning class definitions across files; Anonymous methods for use with delegates; Other new C# features in ...
Read more >C#: Coding With Anonymous Methods, Iterators, And ...
Iterating over collections; Spanning class definitions across files; Anonymous methods for use with delegates; Other new C# features in ...
Read more >C#: IEnumerable, yield return, and lazy evaluation
Let's talk about one of my favorite .NET features: IEnumerable . This interface enables iterating over a collection.
Read more >Is there any trick that allow us to use coroutines with ...
No, C# does not allow yield expressions inside lambdas or anonymous methods. http://blogs.msdn.com/b/ericlippert/archive/2009/08/24/iterator- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This scenario is better served with local functions, which can be iterators. They are going into C# 7.0.
@MadsTorgersen The need of local function means it need to specify a name of function that should actually be anonymous. So if you really think this should implement by local function then should we have syntactic sugar for anonymous local function???
And I think that it would became lambda anyway. So please just allow yield return in lambda. You could just add feature to convert lambda to local function at compile time or anything