question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow C# to use anonymous iterators.

See original GitHub issue

VB.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:closed
  • Created 9 years ago
  • Reactions:7
  • Comments:24 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
MadsTorgersencommented, Aug 15, 2016

This scenario is better served with local functions, which can be iterators. They are going into C# 7.0.

2reactions
Thainacommented, Dec 26, 2016

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found