Racooon
Racooon

Reputation: 1496

How to define a variable as a Method?

An Example:

class SpecialButton
{
   public SpecialButton(ButtonConfig conf, Method definedMethod)
   {
       button = new Button();
       button.Location = conf.Location;
       //etc.
       button.Click += new System.EventHandler(definedMethod);
   }
}

is it possible to define a variable as method? I want to use the delegate for this click event, which comes from outside of this class.

Thank You.

Upvotes: 1

Views: 125

Answers (2)

DeveloperX
DeveloperX

Reputation: 4683

ok,read articles about delegates Delegates Tutorial on MSDN and Introduction to Delegates and Events

Upvotes: 1

Vlad
Vlad

Reputation: 35594

I would use either Action<Object, EventArgs> or just EventHandler.

Upvotes: 3

Related Questions