I have an interface say public interface IofMine{}
and code like this:
interface IItems
{
List<IofMine> MyList;
}
public class Items: IItems{
private List<IofMine> _myList;
public List<IofMine> MyList
{
get{return _myList;}
set{_myList = value;}
}
}
public class ofMine : IofMine
{}
...
Some where in say main I call this functions add1 and add2 tat look like this:
...
public static void add1<T>(Items items) where T : IofMine, new()
{
var temp = items.MyList;
var toAdd = new List<T>();
temp.AddRange(toAdd); // here it talls me : Error Argument 1: cannot convert from 'System.Collections.Generic.List<T>' to 'System.Collections.Generic.IEnumerable<IofMine>'
}
public static void add2<T>(Items items) where T : IofMine, new()
{
var toAdd = new List<T>();
toAdd.AddRange(items.MyList); // here it talls me : Error Argument 1: cannot convert from 'System.Collections.Generic.List<IofMine>' to 'System.Collections.Generic.IEnumerable<T>'
}
So I wonder how to make list from interface be expandable with list from generic template that my function received and vice versa?