小弟又来请教问题了~
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace p2_12
{
     class Program
     {
         static void Main(string[] args)
         {
             BankCard card1 = new BankCard() { money = 1000 };
             Account acc1 = card1;
             Ipay i1 = (BankCard)acc1;
             acc1 = new Account() { money = 500 };
             if (acc1 is BankCard)
                 card1 = (BankCard)acc1;
             Console.WriteLine(card1.money);  
         }
     }
     interface Ipay
     {
         bool pay(decimal price);
     }
     class Account
     {
         public decimal money;
         public void Deposit(decimal x)
         {
             money = money + x;
         }
         public bool Withdraw(decimal x)
         {
             if (money > x)
             {
                 money = money - x;
                 return true;
             }
             else
                 return false;
         }
     }
     class BankCard:Account,Ipay
     {
         public bool pay(decimal price)
         {
             if(money>=price)
             {
                 money=money-price;
                 Console.WriteLine("成功购买{0}元商品",price);
                     return true;
             }
             else
             {
                 Console.WriteLine("金额不足");
                 return false;
             }
         }
     }
}
我觉得这个程序不应该输出1000啊,麻烦大神们帮我看一下,为什么我的调试结果就出来一个1000.。。谢谢了
------解决方案--------------------
card1是个BankCard,money1000
acc1是个Account,money500
acc1不是BankCard
然后显示card1.money
楼主要啥效果