Link to home
Start Free TrialLog in
Avatar of quentinA
quentinAFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Lambda expressions and the Action<Object> delegate

The Action<Object> delegate is used in RelayCommands, DelegateCommands.

Code snippets below:
  public class SimpleDelegateCommand : ICommand
    {
        Action<object> _executeDelegate;

          public SimpleDelegateCommand(Action<object> actionDelegate)
        {
            _executeDelegate = actionDelegate;
        }

etc.

 public class Methods
    {
       // A method that doesn't had any parameters
        public static void NoParameterMethod()
        {
            MessageBox.Show("The Method that doesn't take a parameter was Called");
        }

The question I have is: Why is the following acceptable?

       private ICommand _test2Command = new SimpleDelegateCommand(y => Methods.NoParameterMethod());

That is:
given that the SimpleDelegateCommand needs and Action<object> delegate to be passed as an argument, how can a method that doesn't take any parameters be allowed by the delegate?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial