The type or namespace name 'T' could not be found while Implementing IComparer Interface

I am trying to implement IComparer Interface in my code

public class GenericComparer : IComparer
{
    public int Compare(T x, T y)
    {

        throw NotImplementedException;
    }
}

But this throws an error

Error 10 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

I have no idea, what's going wron. Can any one point out what I am doing wrong?

Jon Skeet
people
quotationmark

Your GenericComparer isn't generic - and you're implementing the non-generic IComparer interface. So there isn't any type T... you haven't declared a type parameter T and there's no named type called T. You probably want:

public class GenericComparer<T> : IComparer<T>

Either that, or you need to change your Compare method to:

public int Compare(object x, object y)

... but then it would be a pretty oddly named class.

people

See more on this question at Stackoverflow