Lambda expressions and the Action<Object> delegate, further question #3

I'm sorry, but I still don't get this.

"Lambda expressions are, in effect, anonymous methods that take one argument, and return a value.
In the case of the Action<T> delegate the return value is ignored."

In my previous question, it was stated:

argument passed into the anonymous method is "x" (or the function pointer to the Debug.Indent method):
ICommand _indentCommand = new SimpleDelegateCommand( x => Debug.Indent() );

What is the return value that is being ignored by the Action<T> delegate?
Does the whole of the lambda expression represent the Action<T> required as the argument for the SimpleDelegateCommand or is it just the left hand side or right hand side?

quentinAAsked:
Who is Participating?
 
lazyberezovskyConnect With a Mentor Commented:
Let's go step by step::
ICommand _indentCommand = new SimpleDelegateCommand( x => Debug.Indent() );
equals to
ICommand _indentCommand = new SimpleDelegateCommand(delegate(object x) { Debug.Indent(); } );
See that signature? delegate void Name(object x)
Debug.Indent() is not a signature of delegate - it is delegate's body.

Going further (replacing anonymous method with named method):
ICommand _indentCommand = new SimpleDelegateCommand(DoSomething);

private void DoSomething(object x)
{
    // paremeter x simply not used
    Debug.Indent();
}

Any questions?
0
 
lazyberezovskyConnect With a Mentor Commented:
And answers to your questions:
1) What is the return value that is being ignored by the Action<T> delegate?
    definition of Action<T>:
    public delegate void Action<T>(T obj);
    It means "any method (either named or anonymous) that excepts one parameter and returns void". There is no return value.

2) Does the whole of the lambda expression represent the Action<T> required as the argument for the SimpleDelegateCommand or is it just the left hand side or right hand side?
   Yes, it all required as parameter.
   See http://msdn.microsoft.com/en-us/library/bb397687.aspx
 

   
   
0
 
quentinAAuthor Commented:
Thanks. I finally understand it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.