Here is a simple generator in C#.
IEnumerable Foo() { int a = 1, b = 1; while(true) { yield return b;
See here; example excerpt below:
module main; import std.stdio; import generators; void genSquares(out int result, int from, int to) { foreach (x; from .. to + 1) yield!result(x * x); } void main(string[] argv) { foreach (sqr; generator(&genSquares, 10, 20)) writeln(sqr); }