I want to have a generic interface which has a property that is the used as the Id property of the derived classes.
I wrote the interface like below:
interface IEntity<T>
{
T Id { get; set; }
}
and the derived classes can use it like below:
public class Employee : IEntity<int>
{
// don't need to define Id property
// public int Id { get; set; }
}
public class Document : IEntity<string> { ... }
Unfortunately, the compiler nags this error:
'Employee' does not implement interface member 'IEntity.Id'
What did i do wrong? thanks.
Edit:
While the accepted answer solves the problem, the @dbc comments helped me to achieve my goal, if i changed the interface IEntity
to abstract class IEntity
it doesn't need to implement the Id property in the derived class.