Why is there a pair in this lambda expression?

Josh Smith's MSDN journal article on MVVM contains a lambda expression that I don't quite understand. What is the purpose of param in this code?

_saveCommand = new RelayCommand(param => this.Save(),
                param => this.CanSave );

Translation into my preferred VB language:

Dim saveAction as New Action(Of Object)(AddressOf Me.Save)
_saveCommand = New RelayCommand(saveAction, Function(param) Me.CanSave)

I would expect to see only param if it is used in CanSave or Save. I'm a little new to lambda expressions. It is strange for me to see a variable that is not declared anywhere and is not used, as far as I can tell. Any explanation would be appreciated.

To put this in context, the constructor for RelayCommand (C #):

public RelayCommand(Action<object> execute, Predicate<object> canExecute)

and in VB:

Public Sub New(ByVal execute As Action(Of Object), _
               ByVal canExecute As Predicate(Of Object))
+5
source share
1 answer

- - , , . , Action(Of Object). , .

, , :

_saveCommand = new RelayCommand(delegate { this.Save(); },
     delegate { return this.CanSave; });

... -. - , . :

_saveCommand = new RelayCommand((Object param) => this.Save(),
     (Object param) => this.CanSave);
+3

All Articles