Shouldn't every class that inherits an interface implement all interface members?

Refresh

April 2019

Views

18 time

0

What is the difference between ClassTemp1 and ClassTemp2<T>?

I thought every class that implements an interface should implement all the interface members but ClassTemp2<T> has no error. Why?

public interface ITemp : IComparable
{
    void Temp();
}

public class ClassTemp1 : ITemp // Error
{

}

public class ClassTemp2<T> where T : ITemp // No Error
{

}

1 answers

0

ClassTemp2 doesn't inherit the interface. You're indicating that T is the ITemp type.

To assign inheritance and type:

public interface ITemp : IComparable
{
    void Temp();
}

public class ClassTemp1 : ITemp // Error
{
}

public class ClassTemp2<T> : ITemp 
                       where T : class 
{
}