How to call an explicitly implemented interface-method on the base class

后端 未结 7 1150
死守一世寂寞
死守一世寂寞 2020-12-05 09:56

I have a situation, where two classes (one deriving from the other) both implement the same interface explicitly:

interface I
{
  int M();
}

class A : I
{
          


        
相关标签:
7条回答
  • 2020-12-05 10:42

    You can't call Explicit interface method in base class,here i solved this issue

    I have two interface -> Interface1 and Interface2

    public interface Interface1
    {      
        string method2();      
    }
    
    public interface Interface2
    {   
        string method22();
    
    }
    

    Main class Method

    class Program
    {
        static void Main(string[] args)
        {
    
            class1 cls = new class1();
            string str = cls.method2();
        }
    }
    

    and my interface implemented class

    class class1 : Interface1, Interface2
    {
    
        #region Interface1 Members
    
        public string method2()
        {
            return (this as Interface2).method22();
        }      
    
        #endregion
    
        #region Interface2 Members      
    
        string Interface2.method22()
        {
            return "2";
        }
    
        #endregion
    }
    
    0 讨论(0)
提交回复
热议问题