私は疑問に思っていました:interface
別のクラスから継承できますか?
からインターフェイスを継承させようとしていますMarshalByRefObject
。
私の意図は、インターフェイスを実装するすべてのクラスもそのクラスから継承することです。
私は疑問に思っていました:interface
別のクラスから継承できますか?
からインターフェイスを継承させようとしていますMarshalByRefObject
。
私の意図は、インターフェイスを実装するすべてのクラスもそのクラスから継承することです。
No, it cannot.
An interface can only specify other interfaces that must be implemented. This is done by using the same syntax as inheritance, but it's something different.
You could use an abstract class instead that inherits from MarshalByRefObject
and and requires your interfaces to be implemented.
Depending on how you need to enforce your requirement, generic constraints might help, too. For generic type parameters, you can set class constraints, like class Argh<T> where T : MarshalByRefObject, ISomeInterface
.
インターフェイスはクラスから継承できません。そのためには、C# は現在サポートされていない実装の多重継承をサポートする必要があります。
IMyInterface
クラス からインターフェイス を派生できると想像してくださいMyClass
。次に、そのインターフェイスを実装する別のクラスを宣言するときは、次のように記述する必要があります。
public class MyImplementingClass: MyBaseClass, IMyInterface
MyBaseClass
ただし、との両方から継承しているため、これは実装の多重継承を意味しますMyClass
。
いいえ。クラスはインターフェイスを実装できます。その逆ではありません。
いいえ、インターフェイスには実装を含めることができないため、クラスから継承することはできません。ただし、から継承する抽象クラスを作成できますMarshalByRefObject
。
No, but an interface can inherit from another interface.