5

how to pass argument as function

subbiah
  • 91
  • 3
  • Refer this link below already present in SO http://stackoverflow.com/questions/380198/how-to-pass-a-function-as-a-parameter-in-c – ckv Jun 25 '10 at 04:15

2 Answers2

6

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);
drharris
  • 11,194
  • 5
  • 43
  • 56
1

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

IBhadelia
  • 291
  • 1
  • 5