그래서 내 자신의 최대 힙을 굴려서 인터페이스를 확장하는 제네릭 클래스를 사용하여 뭔가 잘못하고 있습니다. 나는이 말과 같은 클래스 : 다음제네릭 확장 인터페이스를 사용하는 클래스
class SuffixOverlap:IComparable<SuffixOverlap>
{
//other code for the class
public int CompareTo(SuffixOverlap other)
{
return SomeProperty.CompareTo(other.SomeProperty);
}
}
그리고 내 힙 클래스의 생성 :
class LiteHeap<T> where T:IComparable
{
T[] HeapArray;
int HeapSize = 0;
public LiteHeap(List<T> vals)
{
HeapArray = new T[vals.Count()];
foreach(var val in vals)
{
insert(val);
}
}
//the usual max heap methods
}
을하지만이 작업을 수행하려고하면
LiteHeap<SuffixOverlap> olHeap = new LiteHeap<SuffixOverlap>(listOfSuffixOverlaps);
나는 오류가 발생합니다 : The type SuffixOverlap cannot be used as a type parameter T in the generic type or method LiteHeap<T>. There is no implicit reference conversion from SuffixOverlap to System.IComparable.
어떻게 LiteHeap을 제네릭 클래스 T impl을 사용하는 클래스로 만들 수 있습니까? 에서 IComparable 그래서 난 new LiteHeap<SomeClass>
을 쓸 수 ementing 및 SomeClass가에서 IComparable
는'IComparable'은'에서 IComparable는' –
Mahmoud