Skip to content

Instantly share code, notes, and snippets.

@dlhartveld
Last active December 13, 2015 19:48
Show Gist options
  • Save dlhartveld/4964763 to your computer and use it in GitHub Desktop.
Save dlhartveld/4964763 to your computer and use it in GitHub Desktop.
An example of C# delegates and lambda expressions and their use.
class Delegate
{
delegate int BinOp(int x, int y);
BinOp Plus()
{
return (x, y) => x + y;
}
int Calculate(int x, int y)
{
return Plus()(x, y);
}
void Work()
{
BinOp Times = (x, y) => x * y;
int z = Times(2, 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment