Delegates are types to store reference to functions.
- They are declared like functions with no body
- Delegate keyword is used before return type
- Declaration indicates function signature with return type-params
Example:
namespace NS_x
{
class CL_x
{
delegate void DLG_stateShow(string s1);
static void F_westState(string s1)
{
Console.WriteLine(s1 + " is a west State");
}
static void F_eastState(string s1)
{
Console.WriteLine(s1 + " is a east State");
}
static void Main(string [] args)
{
DLG_stateShow DLG_o_side;
string str_stateName = "nevada";
if (str_stateName == "nevada")
{
DLG_o_side = new DLG_stateShow(F_westState);
}
else
{
DLG_o_side = new DLG_stateShow(F_eastState);
}
DLG_o_side(str_stateName);
}
}
}