How to run a function with parameters by delegate?

  • Thread starter Thread starter Jet Leung
  • Start date Start date
J

Jet Leung

Hi all
I am confused that how to run a function which has parameters by delegate?
please show the example code and tell me more about the delegate.
Thank you!
For example
...
delegate string D_mydelegate(string p1,string p2);
....
// function 1
public string A(string parameter1,string parameter2)
{
//my code..
}
....
D_mydelegate A_delegate=new D_mydelegate(A);
....
And then how to transfer parameters to the function A???
And how to make the function work??
 
Well, you delcared eveything correctly, so now you can treat A_delegate as if you were calling A directly

Console.WriteLine(A_delegate("Hello", World"));
 
also you can invoke the function by "Invoke" method, or DynamicInvoke ...

--
Vladimir Scherbina,
UA, Kiev.

Charlie Williams said:
Well, you delcared eveything correctly, so now you can treat A_delegate as
if you were calling A directly:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top