How to call the SomeWork () method correctly so that a compilation error does not occur?

using System; namespace ConsoleApplication1 { interface IA { void SomeWork(); } class B : IA { void IA.SomeWork() { Console.WriteLine("Some work in B"); } } class Program { static void Main(string[] args) { B a = new B(); a.SomeWork(); } } } 

    1 answer 1

    It is necessary to bring an instance of the class to the interface.

     B a = new B(); ((IA)a).SomeWork(); 

    Or immediately save in the interface:

     IA a = new B(); a.SomeWork();