Xob: 1 Yob: 1
Y X. Changelt .
Delegate X Changelt(Y obj);
X Y. IncrA () IncrB () .
Static X IncrA(X obj) static Y IncrB(Y obj)
IncrA () X . IncrB () Y . - Changelt, .
,
Changelt change = IncrA;
IncrA () , X IncrA (), Y Changelt. , , , , , .
, .
change = IncrB;
IncrB () Y, X. , .
System. Delegate
System. Delegate. , , . System. Delegate .
, . , . -, , . -, , . , . , Windows Paint. . , . , .
, , . , , , . , . , , , . , , . , , .
|
|
3.0, C# : -. C# 2.0, - 3.0. - . #. - #. -, -. , - . , -.
, . delegate. , , . 0 5.
// .
Using System;
// , delegate void Countlt();
class AnonMethDemo { static void Main() {
// , // .
Countlt count = delegate {
// , for (int i=0; i <= 5; i++)
Console.WriteLine(i);
}; //
Count();
}
}
Countlt void. Main () count Countlt, , delegate. , count. , , . .
. delegate, . , .
// , , using System;
// , Countlt , delegate void Countlt(int end);
|
|
class AnonMethDemo2 {
static void Main() {
// . Countlt count = delegate (int end) { for(int i=0; i <= end; i++)
Console.WriteLine(i);
};
Count (3);