How to call a particular explicitly declared interface method in C#

后端 未结 4 901

I have a doubt on how to call the method of particular interface (Say IA or IB or In...) in the following code. Please help me on how to call. I have commented the lines of

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-19 04:00

    In order to call an explicit interface method you must hold a reference to that interface type or cast it:

    IB ib = new Model();
    ib.Display();
    
    IA ia = (IA)ib;
    ia.Display();
    

提交回复
热议问题