将快速完成闭包转换为C#
我正在将一个库从Swift移植到C#,并且在将完成处理程序转换为C#时遇到问题 在Swift中,我有:将快速完成闭包转换为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
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;
您可以查看此网页以了解更多说明:
谢谢!非常好,我会花一分钟阅读你提供的文章谢谢!工作很好,我会花一分钟阅读你提供的文章