gpt4 book ai didi

c# - 没有对 'card' 的隐式引用从 'card' 到 IComparable 的转换

转载 作者:行者123 更新时间:2023-11-30 21:53:39 26 4
gpt4 key购买 nike

如何比较卡列表?我收到此错误,但我不知道这意味着什么或如何修复它。我得到的错误:

the type 'Card' cannot be used as type parameter 'T' in generic type or method 'secondClass'. there is no implicit reference to 'Card' convertion from 'Card' to IComparable

class Node<T>
{
public int id;
public T data;
public Node<T> next;
}

class GameLinkedList<T> where T : IComparable
{
private Node<T> head;
private Node<T> temp;
private int count = 0;

public void AddFront(T t)
{
count++;
temp = head;
Node<T> node = new Node<T>();
node.data = t;
node.id = count;
node.next = temp;
head = node;
}
}

class Bundle
{
//private List<Card> deck1;
GameLinkedList<Card> deck = new GameLinkedList<Card>();
}

class Card
{
private Suit suit;
private Value value;
private string cardName;
}

最佳答案

您的Card 类需要实现IComparable 接口(interface)

MSDN

关于c# - 没有对 'card' 的隐式引用从 'card' 到 IComparable 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33736744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com