Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Threading. tasks;
Namespace consoleapplication1
{
Delegate void myaction ();
Delegate void myaction <t> (t obj );
Delegate void myaction <t1, T2> (T1 Who, T2 say );
Delegate string myfunc ();
Delegate t myfunc <t> ();
Delegate tresult myfunc <t, tresult> (t give );
Delegate tresult myfunc <T1, T2, tresult> (T1 give, T2 N );
Class Program
{
Static void main (string [] ARGs)
{
Console. writeline ("Action ------------------");
Action A = () => {console. writeline ("hello ");};
A. Invoke ();
Action <string> B = x =>{ console. writeline (x );};
B ("hi ");
Action <string, string> C = (x, y) => console. writeline (x + "say" + y );
C ("mr. Du", "hello ");
Console. writeline ("myaction ------------------");
Myaction a1 = A. method. createdelegate (typeof (myaction) as myaction;
A1 ();
Myaction <string> b1 = B. method. createdelegate (typeof (myaction <string>) as myaction <string>;
B1 ("hi1 ");
Myaction <string, string> C1 = C. method. createdelegate (typeof (myaction <string, string>) as myaction <string, string>;
C1 ("mr. Du", "hello1 ");
Console. writeline ("func ------------------");
Func <string> F1 = () => {return "f1 ";};
Console. writeline (F1 ());
Func <string, string> F2 = x =>{ return x + x ;};
String give = "";
Console. writeline (F2 (give) + "Get of" + give );
Func <string, Int, string> F3 = (x, n) =>
{
For (INT I = 0; I <n; I ++)
{
X + = X;
}
Return X;
};
Console. writeline (F3 (give, 3) + "Get of" + give );
Console. writeline ("myfunc ------------------");
Myfunc mf1 = f1.method. createdelegate (typeof (myfunc) as myfunc;
Console. writeline (mf1 ());
Myfunc <string> mf2 = f1.method. createdelegate (typeof (myfunc <string>) as myfunc <string>;
Console. writeline (mf2 ());
Myfunc <string, string> mf3 = f2.method. createdelegate (typeof (myfunc <string, string>) as myfunc <string, string>;
Console. writeline (mf3 (give) + "Get of" + give );
Myfunc <string, Int, string> mf4 = f3.method. createdelegate (typeof (myfunc <string, Int, string>) as myfunc <string, Int, string>;
Console. writeline (mf4 (give, 3) + "Get of" + give );
}
}
}
Delegate conversion, delegate Overloading