Anonymous Method / no type / no return

  • Thread starter Thread starter Andrew Robinson
  • Start date Start date
A

Andrew Robinson

Is there any general purpose delegate that will allow me to call a method
anonymously. The delegate does not pass any data as part of the method
signature and has a void return. Data is passed as part of the method body.
I am thinking something along the line of Action<null>. Just wondering if
there is a simpler method other than declaring the delegate FredDelegate()?

example:

private delegate void FredDelegate();
private void Fred(FredDelegate action)
{
// code here

action();

// more clode here
}

public void Fred()
{
Fred(delegate() { });
}

public void Fred(FredKey key)
{
Fred(delegate() { this.status = key.status; });
}
 
Andrew Robinson said:
Is there any general purpose delegate that will allow me to call a method
anonymously. The delegate does not pass any data as part of the method
signature and has a void return. Data is passed as part of the method body.
I am thinking something along the line of Action<null>. Just wondering if
there is a simpler method other than declaring the delegate FredDelegate()?

ThreadStart or MethodInvoker are the ones I know off the top of my
head. In .NET 3.5 there's plain Action, which is a nicer alternative :)
 
Jon,

Exactly what I was after. Coded my own Action() in a base class with a note
to remove once upgraded to the 3.5 framework.

Thanks
 
Back
Top