I am very new to generics and I am trying to write a simple class which will be generic but also allow sorting of some description on a string member variable.
At the moment I have a basic class but when I try to implement the interface member CompareTo() I get an error at the top telling me it is not implemented. What is the issue here?
using System;
namespace GenericsPracticeConsole.Types
{
class SortableGenericType<T> : IComparable
{
private T t;
private string stringName;
public T name
{
get { return t; }
set { t = value; }
}
public int CompareTo(SortableGenericType<T> ourObject)
{
return stringName.CompareTo(ourObject.stringName);
}
}
}
if (obj.GetType() != GetType()) return -1;
, because then your comparison is no longer antisymmetric or reflexive. – Acetylate