没有办法解决这个问题。你的课foo
是正确的。错误消息说明了一切。foo
不继承PictureBox
。如果foo
是某种图片框,请实现PictureBox
类而不是Control
.
给你一个现实生活中的例子:
interface IAnimal { }
class Dog : IAnimal { public static void Bark() { } }
class Cat : IAnimal { public static void Meow() { } }
的签名与定义的Cat
不同,而没有。定义,而没有。例如,以下带有注释的代码将帮助您理解这一点:Dog
Cat
Cat.Meow()
Dog
Dog
Dog.Bark()
Cat
class Program
{
static void Main(string[] args)
{
Dog myDog = new Dog(); // myDog contains definition for Bark
IAnimal myPet = (IAnimal)myDog; // Cast not necessary.
// myPet's signiature is of Dog, but typeof(myPet)
// is Animal as it was boxed (google for help on this)
Cat myCat = (Cat)myPet // now try and imagine this in real life
// (turning a dog into a cat) [I don't even]
// It doesn't work because Cat doesn't
// contain a definition for Bark()
Cat myDimentedCat = (Cat)(IAnimal)myDog; // which is why this code fails.
}
}
我要展示的内容与以下内容相同
a square is a rectangle, but a rectangle isn't always a square
:
interface IRectangle { }
interface ISquare : IRectangle { }