public class KeyEvent {
private Keys[] keys = null;
public delegate void eventmethod();
private eventmethod em;
private object[] args;
private bool thrown = false;
public bool repeat = true;
public bool isKey(Keys key) {
if (keys == null) return true;
foreach (Keys k in keys) {
if (key == k) return true;
}
return false;
}
public void ThrowEvent() {
if (!repeat && thrown) return;
em.DynamicInvoke(args);
this.thrown = true;
}
public KeyEvent(eventmethod D) {
em = D;
}
public KeyEvent(Keys[] keys, eventmethod D) {
this.keys = keys;
this.KeyEvent(D);
}
public KeyEvent(eventmethod D, object[] args) {
this.args = args;
this.KeyEvent(D);
}
public KeyEvent(Keys[] keys, eventmethod D, object[] args) {
this.args = args;
this.KeyEvent(keys, D);
}
}
嘿,伙计们;这个类不会编译。我得到的错误是:
'BLBGameBase.KeyEvent' does not contain a definition for 'KeyEvent' and no extension method 'KeyEvent' accepting a first argument of type 'BLBGameBase.KeyEvent' could be found (are you missing a using directive or an assembly reference?)
无论如何,调用“this.KeyEvent(D)”或类似代码的三行都会抛出此错误。 我不明白该错误,因为它争辩说没有方法接受“KeyEvent”的第一个参数,但我并没有尝试使用 KeyEvent 调用方法...谢谢。
最佳答案
要从一个构造函数调用另一个构造函数,请使用以下语法:
public KeyEvent(Keys[] keys, eventmethod D)
: this(D)
{
this.keys = keys;
}
就您的代码而言,它正在尝试调用名为 KeyEvent
的常规方法(非构造函数)。
关于c# 构造函数错误 "CS1061" "x does not contain a definition for y",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2012155/