Card.cs
using System;
using System.Collections;
using System.Text;
namespace CardExample
{
public enum Suit
{
红心,
方块,
梅花,
黑桃
}
public enum Rank
{
Ace=1,
_2,
_3,
_4,
_5,
_6,
_7,
_8,
_9,
_10,
J,
Q,
K
}
public class Card
{
public static bool useTrumps;
public static Suit Trumps = Suit.梅花;
public static bool isAceHingh = true;
public readonly Suit suit;
public readonly Rank rank;
public override string ToString()
{
return ""+suit+rank;
}
private Card()
{
}
public Card(Suit newSuit, Rank newRank)
{
suit = newSuit;
rank = newRank;
}
public static bool operator ==(Card card1, Card card2)
{
return (card1.suit == card1.suit) && (card1.rank == card2.rank);
}
public static bool operator !=(Cards card1, Card card2)
{
return !(card1 == card2);
}
public override bool Equals(object card)
{
return this==(Card)card;
}
public override int GetHashCode()
{
return 13*(int)rank+(int)suit;
}
public static bool operator >(Card card1, Card card2)
{
if (card1.suit == card2.suit)
{
if (isAceHingh)
{
return (card1.rank > card2.rank) ^ (card2.rank = Rank.Ace);
}
else
{
return (card1.rank >= card2.rank);
}
}
else
{
if (useTrumps && (card2.suit = Card.Trumps))
{
return false;
}
else
{
return true;
}
}
}
public static bool operator <=(Card card1, Card card2)
{
return !(card1 > card2);
}
}
}
错误 1 运算符“CardExample.Card.operator ==(CardExample.Card, CardExample.Card)”要求也要定义匹配的运算符“!=”
错误 2 运算符“CardExample.Card.operator !=(CardExample.Cards, CardExample.Card)”要求也要定义匹配的运算符“==”
错误 3 运算符“CardExample.Card.operator >(CardExample.Card, CardExample.Card)”要求也要定义匹配的运算符“<”
错误 4 运算符“CardExample.Card.operator <=(CardExample.Card, CardExample.Card)”要求也要定义匹配的运算符“>=”
何解?
我是初学的啊!求各位大虾帮帮小弟!