i am confused. How i may create example of that class? this error said: The type 'type1' cannot be used as type parameter 'T' in the generic type or method ''. There is no implicit reference conversion from 'type1' to 'type2'. But where i am did wrong?
public interface IMyList<T>
{
void Add(T a);
T this[int index] { get; }
int Count { get; }
void Clear();
bool Contains(T item);
}
public class Mylist<T> where T: IMyList<T>
{
public T this[int index]
{
get { return this[index]; }
}
public List<T> array = null;
public int Count()
{
int a = 0;
foreach (var item in array)
{
a++;
}
return a;
}
public Mylist()
{
this.array = new List<T>(0);
}
public void Add(T a)
{
array.Add(a);
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(T item)
{
throw new NotImplementedException();
}
}
class Program
{
static void Main()
{
IMyList<int> list = new Mylist<IMyList<int>>() as IMyList<int>; //cs0311
Mylist<IMyList<int>> mylist = new Mylist<IMyList<int>>(); //cs0311
//a.Add(1);
//Console.WriteLine(a.Count());
}
}