In fact, both of them are the abbreviated form of "agent" entrusted.
First, "action<>" specifies that only input parameters, no return value of the delegate
Delegate's Code:
[CSharp]View Plaincopy
- public delegate void mydelegate (string str);
- public static void hellowchinese (string strchinese)
- {&NBSP;&NBSP;
- console.writeline (
- console.readline ();
- }
- &NBSP;&NBSP;
- Mydelegate d = new mydelegate (hellowchinese);
- d (
After using the action:
[CSharp]View Plaincopy
- Public static void Hellowchinese (string strchinese)
- {
- Console.WriteLine ("Good morning," + Strchinese);
- Console.ReadLine ();
- }
- action<string> action = Hellowchinese;
- Action ("Spring.");
is tantamount to omitting the steps to define a delegate.
Second, func<> this and the above is the same, the difference is that there is a return value!
[CSharp]View Plaincopy
- Public static string Helloenglish (string strenglish)
- {
- return "Hello." + strenglish;
- }
- func<String, string> f = helloenglish;
- Console.WriteLine (f ("Srping ji"));
- Console.ReadLine ();
Action<> and Func<> in C #;