Skip to content

Instantly share code, notes, and snippets.

@richorama
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richorama/80125dd2809bbf620fe8 to your computer and use it in GitHub Desktop.
Save richorama/80125dd2809bbf620fe8 to your computer and use it in GitHub Desktop.
FuncGenerator
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (var x in FuncGenerator(0, 10).Take(10))
{
Console.WriteLine(x(3));
}
Console.ReadKey();
}
static IEnumerable<Func<int, int>> FuncGenerator(int startingPoint, int increment)
{
var count = startingPoint;
while (true)
{
// we could do something interesting here, as we can calculate something for the func
yield return new Func<int, int>((a) =>
{
// I'm sure I could do something interesting here, as execution is deferred
return count * a;
});
count += increment;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment