The second is terrible. It is really equivalent
IMyInterface inst = new MyClass();
but it doesnβt even check that MyClass implements the interface. This is just a way to use var , but explicitly specifying the type elsewhere. Hk.
As a rule, it is cleaner to declare variables using the interface type (in accordance with the above or the third option), if this is all you rely on, it makes it clear to the user that you do not need any additional members declared by the class. For more information, see "What does an interface program mean?" .
Note that none of this has anything to do with implementing an interface. MyClass is a class that implements an interface. It is simply related to using the interface.
source share