Skip to content

Instantly share code, notes, and snippets.

@vaclavbohac
Created March 24, 2011 11:05
Show Gist options
  • Select an option

  • Save vaclavbohac/884895 to your computer and use it in GitHub Desktop.

Select an option

Save vaclavbohac/884895 to your computer and use it in GitHub Desktop.
Example of anonymous methods in C#.
using System;
namespace Example
{
delegate void Callback(int x);
class Application
{
public static void Main(string[] args)
{
Application app = new Application();
app.run();
}
public void run()
{
Callback foo = delegate (int x) {
Console.WriteLine((x * x).ToString());
};
bar(6, foo); // Prints 36.
}
public void bar(int x, Callback cb)
{
cb(x);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment