I’ve used delegates when designing win forms in .NET… i.e. drag/drop a button, double click, and fill in the myButton_click event. I want to understand how to create and use user-defined delegates in C#.
How are user-defined delegates used and created in C# ?
I suggest reading a tutorial on the topic.
Basically, you declare a delegate type:
Then you can either assign and call it directly:
Or you create an event:
Then you can add an event handler from outside like this:
Visual Studio is helpful with this. After you entered the +=, just press tab-tab and it will create the handler for you.
Then you can fire the event from inside the object:
That’s the basic usage.