//Jack的账户信息 账号、余额、姓名、年龄 PersonAccount Jack = new PersonAccount("201506", 2000, "Jack", 20); //Tom的账户信息 PersonAccount Tom = new PersonAccount("201507", 5000, "Tom", 55); /** *Jack、Jack2为引用类型,所以赋值时,Jack只是将引用地址赋给Jack2,两者指向了同一块内存区域A; **/ PersonAccount Jack2 = Jack; //Jack 从账户取走500,剩余1500 Jack.AccountMoney = 1500; MessageBox.Show("Jack2的账户(201506)余额为:" + Jack2.AccountMoney);//输出1500 /** *此时Tom将引用地址赋给Jack,两者指向了同一块内存区域B。Jack2的引用地址不变,指向内存区仍为A; **/ Jack = Tom; MessageBox.Show("Jack2的账户(201506)余额为:" + Jack2.AccountMoney);//输出1500 MessageBox.Show("Jack的账户(201507)余额为:" + Jack.AccountMoney);//输出5000
时间: 2024-09-19 22:03:56