How to call explicit interface implementation methods internally without explicit casting?

后端 未结 7 757
谎友^
谎友^ 2020-12-08 18:44

If I have

public class AImplementation:IAInterface
{
   void IAInterface.AInterfaceMethod()
   {
   }

   void AnotherMethod()
   {
      ((IAInterface)this)         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 19:20

    Tried this and it works...

    public class AImplementation : IAInterface
    {
        IAInterface IAInterface;
    
        public AImplementation() {
            IAInterface = (IAInterface)this;
        }
    
        void IAInterface.AInterfaceMethod()
        {
        }
    
        void AnotherMethod()
        {
           IAInterface.AInterfaceMethod();
        }
    }
    

提交回复
热议问题