Created
March 24, 2011 11:05
-
-
Save vaclavbohac/884895 to your computer and use it in GitHub Desktop.
Example of anonymous methods in C#.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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