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

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

If I have

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

   void AnotherMethod()
   {
      ((IAInterface)this)         


        
7条回答
  •  自闭症患者
    2020-12-08 19:18

    You can introduce a helper private property:

    private IAInterface IAInterface => this;
    
    void IAInterface.AInterfaceMethod()
    {
    }
    
    void AnotherMethod()
    {
       IAInterface.AInterfaceMethod();
    }
    

提交回复
热议问题