これを修正する方法はありません。あなたのクラスfooは正しいです。エラーメッセージはそれをすべて説明しています。foo継承しませんPictureBox。fooがある種のピクチャ ボックスである場合は、 ではPictureBoxなくクラスを実装しControlます。
実際の例を挙げると:
interface IAnimal { }
class Dog : IAnimal { public static void Bark() { } }
class Cat : IAnimal { public static void Meow() { } }
の署名はas defined とCatは異なりますが、そうではありません。を定義しますが、定義しません。たとえば、コメント付きの次のコードは、これを理解するのに役立ちます。DogCatCat.Meow()DogDogDog.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 { }