Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#=>;论辩_C# - Fatal编程技术网

C#=>;论辩

C#=>;论辩,c#,C#,因此,我的代码中包含以下内容: excluirCommand = new RelayCommand(param => this.Deletar(), param => this.PodeDeletar()); RelayCommand构造函数接收一个操作类型和一个谓词类型作为参数 我的问题是,如果没有param=>,this.Deletar()不能用作构造函数的参数(this.Deletar()是一个无效类型的方法),那么param=>到底做什么?该参数是动作委托的输入参数。你的行

因此,我的代码中包含以下内容:

excluirCommand = new RelayCommand(param => this.Deletar(), param => this.PodeDeletar());
RelayCommand构造函数接收一个
操作
类型和一个
谓词
类型作为参数


我的问题是,如果没有
param=>
this.Deletar()
不能用作构造函数的参数(
this.Deletar()
是一个无效类型的方法),那么
param=>
到底做什么?

该参数是动作委托的输入参数。你的行动可能需要,也可能不需要

param=>this.Deletar()
在逻辑上等价于如下方法:

public void MyDelegate(object param)
{
    this.Deletar();
}

为了使Deletar方法符合RelayCommand方法所需的签名,它需要返回void并接受单个对象参数,如上面的
MyDelegate

你在问为什么
this.Deletar()
,这是一个无效方法,而不是一个
操作
?确切地说,我的意思是为什么该操作接受一个无效方法?据我所知,如果一个参数的类型是determined,那么在方法调用时需要给它相同的类型。如果在当前的回答中没有理解这一点,请让我知道,我会进一步解释,因为动作类型是委托,所以这是有效的?我对代表不太了解,也许这就是问题所在。我的意思是,如果“Action”只是我创建的某个随机类,那么这种语法会起作用吗?