The code is as follows:
Copy Code code as follows:
static void Main (string[] args)
{
Console.WriteLine (Exec (Getset));
Console.readkey ();
}
Defines a delegate that is used to pass a method as a parameter to exec.
Public delegate string Getresultdelegate ();
public static string Get ()
{
return ' get ';
}
public static string Gettest ()
{
return "Gettest";
}
public static string Getset ()
{
return "Getset";
}
public static string Exec (Getresultdelegate getresult)
{
return GetResult ();
}
With a delegate, one method can be used as the parameter of another method, and the direct execution of the parameter is OK. Similar to JavaScript functions, functions in JavaScript can also be used as arguments to another function. JavaScript can directly use the function name to do parameters, and C # must be commissioned, turn a corner, achieve the same function!