I'm trying to understand the generic interface as described in this
My example has an interface:
public interface ITest<T> where T: class
{
T GetByID(int id);
}
I have a class that implements the interface, using LINQ to enties in project Data, which contains the class myClass:
public class Test<myClass> : ITest<myClass> where myClass : class
{
Data.myEntities _db = new Data.myEntities();
public myClass GetByID(int id)
{
var item = _db.myClass.First(m => m.ID == id);
return item;
}
}
This produces an error saying "Cannot implicitly convert type 'Data.myClass' to 'myClass', but if I change public class Test<myClass> to public class Test<Data.myClass> I get the "Type parameter declaration must be an identifier not a type".
I'm obviously missing something, because I don't understand what's going on here. Can anyone explain it, or point to somewhere that might explain it better?
Thanks.