Last active
February 11, 2020 22:53
-
-
Save ohlawdie/7edb1d1baf2ab23dbda78a86b17ed737 to your computer and use it in GitHub Desktop.
Callback #delegate #callback
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
| If you're used to function pointers in C, a delegate is basically a pair of pointers rolled into one: | |
| A pointer to an object (optional) | |
| A pointer to a method of that object | |
| That means a single delegate passes all the information needed to locate a function in your program, whether it's a static method or associated with an object. | |
| You define them like this in C#: | |
| public delegate void FooCallbackType( int a, int b, int c ); | |
| When you want to use them, you make delegate out of the function you want to call: | |
| class CMyClass | |
| { | |
| public void FunctionToCall( int a, int b, int c ) | |
| { | |
| // This is the callback | |
| } | |
| public void Foo() | |
| { | |
| FooCallbackType myDelegate = new FooCallbackType( | |
| this.FunctionToCall ); | |
| // Now you can pass that to the function | |
| // that needs to call you back. | |
| } | |
| } | |
| ///are delegates references |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment