Pointing Problems
private void button1_Click(object sender, EventArgs e)
{
Card Card1 = new Card();
Card Card2 = new Card();
Card1.Value = 3;
Card1.Suit = 3;
Card2 = Card1;
Card2.Suit = 2;
}
public class Card
{
public int Suit;
public int Value;
public Card()
{
Suit = 0;
Value = 0;
}
}
I step through the Button1 code and any changes on Card2 are updated across to Card1 like they were the same or if card2 were simply pointing to card1. What have I done wrong?
THanks
Roei BarPosted Sep 1, 2009, 10:22 AM
KayPosted Aug 31, 2009, 4:17 PM
Roei BarPosted Aug 31, 2009, 4:15 PM
Card2 = Card1
when you did that you actually told the compiler to put a pointer from Card1 to Card2
meaning that Card2 is actually Card1.