我有一个父类,其中包含一些导入的方法:
class Parent
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
然后我有另一个继承自这个Parent类的类
class Child : Parent
{
GetForegroundWindow(); // intellisense cannot find it
}
这是否意味着我必须围绕父类中导入的GetForegroundWindow()方法创建一个包装器方法,以便在子类中继承和使用它?
答案 0 :(得分:2)
将GetForegroundWindow调用放在某个类方法中,而不是直接在类中。
class Child : Parent { void Foo() { GetForegroundWindow(); } }