C# delegate

delegate is similar to the pointer of C++. A delegate has parameters and return type, and it can represent methods with the same paramters and return type.

public delegate string show(string s, int i);

For example, the Math methods can be represented by a delegation.
public delegate double dg(double db);
dg dlg = new dg(System.Math.Cos);
double res = dlg(2.3); //-0.666276021279824
dg dlg2 = new dg(System.Math.Sin);
double res2 = dlg2(2.3); //0.74570521217672


endmemo.com © 2024  | Terms of Use | Privacy | Home