Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.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#_Swift_Delegates_Closures_Completionhandler - Fatal编程技术网

将快速完成闭包转换为C#

将快速完成闭包转换为C#,c#,swift,delegates,closures,completionhandler,C#,Swift,Delegates,Closures,Completionhandler,我正在将一个库从Swift移植到C#,并且在将完成处理程序转换为C#时遇到问题 在Swift中,我有: public typealias myChangeHandler = (progress: Double, myView: MyCustomView) private var myChangeClosure: myChangeHandler? public func myChangeClosure(_ completion: myChangeHandler) { myChangeC

我正在将一个库从Swift移植到C#,并且在将完成处理程序转换为C#时遇到问题

在Swift中,我有:

public typealias myChangeHandler = (progress: Double, myView: MyCustomView)

private var myChangeClosure: myChangeHandler?

public func myChangeClosure(_ completion: myChangeHandler) {
    myChangeClosure = completion
}
Func<double, MyCustomView> MyChangeType;

public void MyChangeClosure(Func<double, MyCustomView> completion) 
{
    MyChangeType = completion;
}
可以这样称呼:

myChangeClosure?(progress: myProgress, view: self)
localInstance.myChangeClosure() {
    (progress: Double, myView: MyCustomView) in 
    textLabel.text = "\(Int(progress * 100.0))%"
}
或者像这样:

myChangeClosure?(progress: myProgress, view: self)
localInstance.myChangeClosure() {
    (progress: Double, myView: MyCustomView) in 
    textLabel.text = "\(Int(progress * 100.0))%"
}
在C#中,我也尝试过这样做:

public typealias myChangeHandler = (progress: Double, myView: MyCustomView)

private var myChangeClosure: myChangeHandler?

public func myChangeClosure(_ completion: myChangeHandler) {
    myChangeClosure = completion
}
Func<double, MyCustomView> MyChangeType;

public void MyChangeClosure(Func<double, MyCustomView> completion) 
{
    MyChangeType = completion;
}
我的问题
如何将上面的Swift completion功能转换为C#?

Func first generic是返回类型,在您的例子中是double。您想要的是使用操作:

Action<double, MyCustomView> MyChangeType;
您可以查看此网页以了解更多说明:


Func first generic是返回类型,在您的情况下是double。您想要的是使用操作:

Action<double, MyCustomView> MyChangeType;
您可以查看此网页以了解更多说明:


谢谢!非常好,我会花一分钟阅读你提供的文章谢谢!工作很好,我会花一分钟阅读你提供的文章