C#/Lambda:下面的param指的是什么?
我正在查看 此处 中的代码
/// <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;
}
}
param
>参数=> this.OnRequestClose() 指的是?
I am looking at the code from 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;
}
}
what does param
in param => this.OnRequestClose()
refer to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
RelayCommand
可能是接受单个参数的委托类型,或者是本身在构造函数中采用此类委托类型的类型。您正在声明一个匿名方法,简单地说“调用时,我们将获取传入值(但随后不使用它),并调用OnRequestClose
。您还可以(也许更清楚):在使用它的其他用途中可能更清楚,例如:
其中 lambda 是“给定一个
item
,获取item
的SomeValue
”。在您的情况下,lambda 是“给定param
,忽略param
并调用OnRequestClose()
”RelayCommand
is presumably a delegate-type that accepts a single parameter, or a type that itself takes such a delegate-type in the constructor. You are declaring an anonymous method, saying simply "when invoked, we'll take the incoming value (but then not use it), and callOnRequestClose
. You could also have (maybe clearer):It is probably clearer in other uses where it is used, for example:
where the lambda is "given an
item
, obtain theitem
'sSomeValue
". In your case the lambda is "givenparam
, ignoreparam
and callOnRequestClose()
"参数=> this.OnRequestClose() 是 lambda
或
操作
我不确定是哪个
所以它只是一个由某些东西调用的函数的表达式,它将传递一个参数,该参数将是“param”然后不使用
param => this.OnRequestClose() is lambda
or
Action
I'm not sure which
So it's just an expression for a func that is called by something, that will pass an argument which will be 'param' an then not used
没有什么。该行定义了表示函数的 lambda 表达式。该函数具有如下签名: Foo(T param) 其中 T 将是编译器根据被调用构造函数的参数类型推断出的特定类型。
Nothing. The line defines a lambda expression representing a function. That function have a signature like: Foo(T param) where T will be a specific type infered by the compiler based on the type of the argument of the construtor being called.
param 是 lambda 表达式的唯一参数 ( param=>this.OnRequestClose() )
当您实例化 ICommand 对象时,param 可能包含从 UI 传递到此 ICommand 的参数。在您的情况下,该参数未在命令中使用(它不会出现在 lambda 表达式的右侧)。
param is the only parameter of your lambda expression ( param=>this.OnRequestClose() )
As you are instantiating an ICommand object, param would probably contain the parameter passed to this ICommand from the UI. In your case, the parameter is not used in the command (it does not appear on the right side of the lambda expression).