Compilation Error: “The modifier 'public' is not valid for this item” while explicitly implementing the interface

后端 未结 5 1535
遥遥无期
遥遥无期 2020-12-02 16:33

I am getting this error while creating a public method on a class for explicitly implementing the interface. I have a workaround: by removing the e

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 17:02

    When we want to go with implicit implementation for the above example, following would be the code.

        interface I1 { void M(); }
    interface I2 { void M(); }
    
    class C : I1, I2
    {
        public void M() { ... }
    }
    
    C c = new C();
    c.M();  // Ok, no ambiguity. Because both Interfaces gets implemented with one    method definition.
    

提交回复
热议问题