C # / Lambda: What about a parameter in the following?

I look at the code here

/// <summary>
/// Returns the command that, when invoked, attempts
/// to remove this workspace from the user interface.
/// </summary>
public ICommand CloseCommand
{
    get
    {
        if (_closeCommand == null)
            _closeCommand = new RelayCommand(param => this.OnRequestClose());

        return _closeCommand;
    }
}

that paramin param => this.OnRequestClose()belongs to?

+5
source share
4 answers

RelayCommandpresumably is the type of delegate that takes one parameter, or the type that itself accepts that type of delegate in the constructor. You declare an anonymous method, saying simply: “when we call, we take the input value (but do not use it) and call it OnRequestClose. You may also have (perhaps a clearer one):

_closeCommand = new RelayCommand(delegate { this.OnRequestClose(); });

It is probably clearer for other purposes where it is used, for example:

var ordered = qry.OrderBy(item => item.SomeValue);

" item, item SomeValue". " param, param OnRequestClose()"

+16

param = > this.OnRequestClose() - lambda

Func<sometype_that_param_is,sometype_that_OnRequestClose_Is>

  

,

, func, -, , "param",

+1

. -, . ​​, : Foo (T param), T , , .

+1

param - (param = > this.OnRequestClose())

ICommand, , , , ICommand . ( ).

+1

All Articles