类 实例相等情况的问题
程序代码:
Card Card1 = new Card((Suit)1, (Rank)1); Card Card2 = Card1; Card Card3 = new Card((Suit)1, (Rank)1); if (Card1 == Card2) Console.WriteLine("Card1==Card2"); if (Card1.Equals(Card2)) Console.WriteLine("Card1 Equals Card2"); if (Card1 == Card3) Console.WriteLine("Card1==Card3"); if (Card1.Equals(Card3)) Console.WriteLine("Card1 Equals Card3"); Card1=new Card((Suit)2,(Rank)2); Console.WriteLine(Card1); Console.WriteLine(Card2); if (Card1 == Card2) Console.WriteLine("Card1==Card2"); if (Card1.Equals(Card2)) Console.WriteLine("Card1 Equals Card2");
Card1==Card2
Card1 Equals Card2
The Deuce of Hearts
The Ace of Diamonds
请按任意键继续. . .
为什么Card1与Card3,无论用==还是Equals都不相等呢
修改Card1的值也不影响Card2的值