.net - Creating objects from an interface in C# -


Is it possible, only to give an interface, to create an object from this?

Something like this:

var obj = new IWidget ();

(I know this code is not correct - VS lives can not create an example of IWidget)

I am in a context where The reference to my project is the interface, and I want to make concrete objects and return them with a method - but I can not understand how to create objects from the interface.

You can not create an object from an interface. You can create an object from a class using that interface.

For example:

  IList & lt; String & gt; X = new iILIT & lt; String & gt; ();  

will not work.

  IList & lt; String & gt; X = new list & lt; String & gt; ();  

.

The interface can not be created, only the objects that use the interface can be made.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -