简体   繁体   English

接口不需要实现方法

[英]Interface not having requirement to implement methods

MY main class... 我的主要班级......

[Serializable]
    public class SVO : Operation, IAddSizeAbility, IRemoveSizeAbility
    {
        public SerializableDictionary<string, SerializableDictionary<string, decimal>> Data = new SerializableDictionary<string, SerializableDictionary<string, decimal>>();



        public SVO() //Default Constructor
        {
            SerializableDictionary<string, decimal> line = new SerializableDictionary<string, decimal>();
            line.Add("Size - 0", 0.00M);
            Data.Add("OP - 0", line);

        }

        public void AddSize()
        {
            throw new NotImplementedException();
        }
    }

My interfaces... 我的界面......

public interface IAddSizeAbility
    {
        void AddSize();
    }

 public interface IRemoveSizeAbility
    {
        void RemoveSize();
    }

The Issue is although I implement the IAddSizeAbility interace correctly I have not implemented the IRemoveSizeAbility but yet it lets me compile is this a bug? 问题是虽然我正确地实现了IAddSizeAbility interace但我没有实现IRemoveSizeAbility但是它让我编译这是一个错误吗?

I can't replicate the issue when i create a new set of interfaces classes. 当我创建一组新的接口类时,我无法复制该问题。

I have included image so you can see there is no red underline under the interface that is not implemented 我已经包含了图像,因此您可以看到未实现的界面下没有红色下划线

我已经包含了图像,因此您可以看到未实现的界面下没有红色下划线

And an image of my test which does what you would expect. 我的测试图像可以满足你的期望。 我的测试图像可以满足你的期望。

When you declare a class of certain type as implementing an interface and that type inherits from another type that is already implementing the interface , the compiler would still be satisfied as the type does not break the contract. 当您将某个class声明为实现interface并且该类型继承自已实现该interface另一个类型时,编译器仍然会满意,因为该类型不会破坏合同。

In your case, since Operation already implements IRemoveSizeAbility , you're good to go. 在你的情况下,由于Operation已经实现了IRemoveSizeAbility ,你很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM