עליך להתחבר בכדי להוריד קבצים מהאתר
על מנת להבטיח שמשאבינו לא ינוצלו לרעה.
Anonymous Methods |
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Net.NetworkInformation;
4 : using System.Text;
5 :
6 : namespace AnonymousMethod01
7 : {
8 : delegate void MyDelgate();
9 : class Program
10 : {
11 : static void Main(string[] args)
12 : {
13 : // Old Fashion delegate
14 : MyDelgate my_delegate1 = DoSomething;
15 : my_delegate1();
16 :
17 : // Anonymous Method delegate
18 : MyDelgate my_delegate2 = delegate()
19 : {
20 : Console.WriteLine(invoke delegate using anonymous method);
21 : };
22 : my_delegate2();
23 : }
24 : public static void DoSomething()
25 : {
26 : Console.WriteLine(Invoke delegate in the old fashion way);
27 : }
28 : }
29 : }
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Text;
4 :
5 : namespace AnonymousMethod02
6 : {
7 : delegate double MyDelegate(double num1,double num2);
8 : class Program
9 : {
10 : static void Main(string[] args)
11 : {
12 : MyDelegate mul_delegate = delegate(double num1, double num2)
13 : {
14 : return num1 * num2;
15 : };
16 : double result = mul_delegate(10,20);
17 : Console.WriteLine(result);
18 : }
19 : }
20 : }
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Text;
4 :
5 : namespace Anonymous_Method03
6 : {
7 : delegate void MyDelegate(double num1, double num2);
8 : class Program
9 : {
10 : static void Main(string[] args)
11 : {
12 : MyDelegate calculation_delegate = delegate(double num1, double num2)
13 : {
14 : Console.WriteLine(Mul = {0}, num1 * num2);
15 : };
16 : calculation_delegate += delegate(double num1, double num2)
17 : {
18 : Console.WriteLine(Sum = {0}, num1 + num2);
19 : };
20 : calculation_delegate += delegate(double num1, double num2)
21 : {
22 : Console.WriteLine(Sub = {0}, num1 - num2);
23 : };
24 : calculation_delegate += delegate(double num1, double num2)
25 : {
26 : Console.WriteLine(Div = {0}, num1 / num2);
27 : };
28 :
29 : calculation_delegate(10, 20);
30 : }
31 : }
32 : }
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Linq;
4 : using System.Text;
5 : using System.Threading.Tasks;
6 :
7 : namespace AnonymousMethods04
8 : {
9 : delegate void MyDelegate(string msg);
10 : class Program
11 : {
12 : public static event MyDelegate MyEvent;
13 : static void Main(string[] args)
14 : {
15 : MyEvent += delegate(string msg)
16 : {
17 : Console.WriteLine(msg1 : {0}, msg);
18 : };
19 : MyEvent(Event Invoked);
20 : }
21 : }
22 : }