Implementing 2 Interfaces with 'Same Name' Properties

后端 未结 8 1951
天涯浪人
天涯浪人 2021-01-04 22:50

This seems like a reasonable (and maybe simple?) scenario, but how would you do the following:

Lets say I have 2 interfaces:

Interface ISimpleInterfa         


        
8条回答
  •  遥遥无期
    2021-01-04 23:25

    In C#, an implicit implementation (with the set) can satisfy both of these:

    class Foo : ISimpleInterface, IExtendedInterface
    {
        public string ErrorMsg { get; set; } 
        public string SomeOtherProperty {get; set;}
    }
    

    If you want to change it, you can use explicit implementation ("Implements" in VB?) - in C#:

    string ISimpleInterface.ErrorMsg
    {
        get { return ErrorMsg; } // or something more interesting
    }
    

提交回复
热议问题