Search code examples
c#classoopmethodsinterface

I have this code with a class which has a method with type of inteface created in my project , anyone know what does it mean?


Here is my class with the interface type method

internal class MyClass
    {
        public static IMainInterface MyMethod(Main main)
        {
           ///some code
        }
    }

Solution

  • It means that the method returns an instance of a class that implements the IMainInterface interface.

    This is often done for design reasons; in particular, it's usually a good practice to program to interfaces rather than concrete implementations. By analogy, when you learn to drive, you learn to drive cars "in general", not just a Ford Focus. You know how to use all cars to the extent that their interface is the same.