Interface on left side

c#

Solution

`P` is of type `IEnumerable<string>`

Here you are declaring the type of the local variable `P`.

`P` holds the type of `IEnumerable<string>`, and while you aren't instantiating the interface directly, you can instantiate a concrete class but simply hold a reference to the interface.

The instance returned here by the `Where()` call needs to only adhere to the contract that `IEnumerable<string>` defines.

Problem

I know that we can't create instance of `Interface`. but why we can write `Interface` on left side? Are those only references of Interface (for classes that implement this one) instead instance? If we can't create instance of Interface, what type is `P` in this example? ``` string[] names = {"John", "Bob", "Mark"}; IEnumerable<string> P = names.Where(n => n.Contains('o')); ```

Original source

Related problems