的C#interface
是像在Objective-C ,id<UIGestureRecognizerDelegate>
意味着對象實現在UIGestureRecognizerDelegate
定義的方法。因此,在C#同樣的事情可能是(主要思想,在IDE未測試):
interface UIGestureRecognizerDelegate {
public bool gestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer);
}
class Example {
public UIGestureRecognizerDelegate gestureDelegate; //the equivalent
}
並符合接口的類:
public class ExampleViewController:UIViewController,UIGestureRecognizerDelegate {
var example = Example();
public ExampleViewController() {
this.example.gestureDelegate = this;
}
//implements the methods of interface UIGestureRecognizerDelegate
public bool gestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer) {
//......
}
}
是的,它是等價的。 – KKRocks
@property是否意味着是一個靜態參數? – Leze
屬性聲明,因爲我們希望這個變量在類之外。是的,它關鍵字爲目標C中的定義屬性。 – KKRocks