Delegates in C#

Delegates in C#


So what are Delegates? And why do we need them. Delegates are basically pointers to functions (C, C++ parlance). Delegates are reference type variables holding reference to a method. 

First off lets write some code to demonstrate how Delegates are declared and used.

This is a basic example of Delegate. At line 7 we are declaring a delegate

public delegate int ADelegate(int num); 
 On line 10 we assign a method to this delegate

ADelegate md=SquareNum;
And then we call upon the method using the delegate reference.

Note: The delegate must have the same signature as the method that it is referencing.

We can reference another method by the same delegate without any problem. (The signature should be the same)

On line 12 we reference another method
md=CubeNum;

Use of Delegates in Events

Delegates are best exemplified by their use in events. For e.g on a Button Event we can call a method using the below code.

button1.Click+=BTN_CLICK_HANDLER; 
For eg:

button1.Click+=button1_click;

We can then define button1_click as

private void button1_click(object sender, EventArgs e)
{

}
 

Running Drupal in Docker

I will assume that you have already installed docker. If you haven't installed docker please visit https://www.docker.com/ to download a...