这是 C#程序设计的例子,我在 VS2015 和 2013 上调试的输出结果和书上正好相反!我的输出是账号 001 余额 200 ,账号 002 余额 100 。
求大侠指点!
代码如下:
using System;
namespace P3_6
{
    class Program
    {
        static void Main(string[] args)
        {
            Account a1 = new Account() { ID = "001" };
            EditAccount(a1);
            a1.Query();
            ChangeAccount(ref a1);
            a1.Query();
        }
static void EditAccount(Account a)
    {
        a.Money = a.Money * 2;
        a = new Account() { ID = "002" };
    }
    static void ChangeAccount(ref Account a)
    {
        a.Money = a.Money * 2;
        a = new Account() { ID = "002" };
    }
}
class Account
{
    public string ID;
    public decimal Money = 100;
    public void Query()
    {
        Console.WriteLine("账号{0} 余额{1}", ID, Money);
    }
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.