开发者

passing function as argument in the function

开发者 https://www.devze.com 2023-01-04 13:13 出处:网络
how开发者_开发百科 to pass argument as functionYou\'re probably looking for delegates. public delegate void MyDelegate(int myInt, string myString);

how开发者_开发百科 to pass argument as function


You're probably looking for delegates.

public delegate void MyDelegate(int myInt, string myString);
public void FunctionToCall(int i, string s)
{
    Console.WriteLine(s + " [" + i.ToString() + "]");
}
public void MethodWithFunctionPointer(MyDelegate callback)
{
    callback(5, "The value is: ");
}

And then, to call it:

MethodWithFunctionPointer(FunctionToCall);


Make argument as delegate, and call function with address of function which should match with delegates

0

精彩评论

暂无评论...
验证码 换一张
取 消