# 一道递归题的函数

0

`            Dictionary<string, int> A = new Dictionary<string, int>();            A.Add("电脑",20);            A.Add("键盘", 30);            A.Add("鼠标", 90);            A.Add("显示器", 120);`

`  public int Buy(Dictionary<string,int> A,decimal TotalMoney)`

0
`static void Main(string[] args)        {            Dictionary<String, Int32> productList = new Dictionary<string, int>();            productList.Add("电脑", 20);            productList.Add("键盘", 30);            productList.Add("鼠标", 90);            productList.Add("显示器", 120);            int totalMoney = 2000;            Buy(productList, ref totalMoney);            Console.ReadLine();        }        public static void Buy(Dictionary<String, Int32> _productList, ref Int32 _totalMoney)        {            KeyValuePair<String, Int32> product = _productList.First();            Console.WriteLine(String.Format("正在购买“{0}”,价格为：{1}···", product.Key, product.Value));            _totalMoney -= product.Value;            _productList.Remove(product.Key);            System.Threading.Thread.Sleep(2000);            Console.WriteLine(String.Format("购买“{0}”后,余额为：{1}", product.Key, _totalMoney));            Console.WriteLine(Environment.NewLine);            System.Threading.Thread.Sleep(3000);            if (_productList.Count > 0)                Buy(_productList,ref _totalMoney);        }`

0

0

0

您需要登录以后才能回答，未注册用户请先注册