It is possible, given only an interface, to create an object from this?
Something like:
var obj = new IWidget();
(I know this code isn’t right – VS stays cannot create an instance of IWidget)
I’m in a context where my project has references to the interfaces, and I want to create concrete objects and return them from a method – but I can’t figure out how to create the objects purely from the interfaces.
You can’t create an object from an interface. You can create an object from a class that uses that interface.
For example:
will not work.
will.
Interfaces cannot be created, only objects that use the interface can be created.