c# - Delegates with specific arguments -
i'll try keep simple can. have delegate del
void()
(no arguments). have function func(int)
. have 2 variables , b. want able a()
, run func(10)
, , able b() , run func(43)
. know can have delegate void(int)
have function func2(int, int)
. , variable c run func2(21,6)
. need a, b , c same type of variable.
it sounds have this
public delegate void del(); public class myclass { public static void func(int value) { } public static void func2(int value1, int value2) { } }
and need variables a
, b
, c
declared , initialized delegate type such call func(10)
, func(43)
, func2(21, 6)
respectively when invoked.
the code a
del = () => myclass.func(10);
the code b
del b = () => myclass.func(43);
and, code c
del c = () => myclass.func2(21, 6);
a
, b
, c
of type del
you express as:
del = new del(() => myclass.func(10));
or
del = new del(callfuncwithvalue10); public static void callfuncwithvalue10() { myclass.func(10); }
or
del = callfuncwithvalue10;
Comments
Post a Comment