What exactly is the official name of the yield return
concept?
public IEnumerable<T> Bar() {
...
yield return foo;
...
}
I've heard(read) it being referred to as:
- Iterator
- IEnumerabe
- Generator
- <your choice>
Isn't an iterator just some "thing" that iterates over something? A List<T>
is an IEnumerable<T>
, so doesn't seem reasonable as well.
A lot of answers here on SO that talk about yield return
use one of these two terms.
What about "generators"? Or does that only apply when you're "conjuring up values out of thin air", e.g. the Fibonacci Numbers where you don't need a data collection as a source?
The principal it is useful for though is "Coroutine". See Wikipedia.
It's called an iterator, check out this MSDN page
As a general concept in a non-language specific way, "generator" is probably the most common term. That's what I'd use if I were talking to someone who wasn't familiar with C#.
The method itself is an iterator in C# specification terminology. The implementation is an iterator block.
From section 10.14 of the C# 4 spec:
That's the terminology I'd use when talking about C# specifically.