I would like to be able to do something like this :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
You're not going to be able to use a concrete type unless you do it behind the scenes. The problem is that you can both Get and Set the Property.
Your interface specifies that the property is of type IEnumerable. HashSet implements IEnumerable. That means the following should work just fine:
IFoo instance = new Bar();
instance.integers = new HashSet();
But since you're trying to implement the interface using the concrete type List, there's no way that assignment can work.
The easiest fix, assuming you don't constantly need to re-assign the collection, would be to only specify a getter for the collection:
public interface IFoo
{
IEnumerable Integers { get; }
}
public class Bar
{
public List Integers { get; private set; }
public Bar(List list)
{
Integers = list;
}
}