晕了,关于对象引用
在看JAVA核心技术时候,书上说对象引用是值传递,不太明白,然后我就照着代码把C#的敲出来,试试C#是不是也是这样,结果和JAVA结果一样,真晕,不太明白,C#里边如果传递是对象引用的话,那我在方法里边进行的修改,应该是能影响的啊。。可是为什么不行。。求解。。谢谢
class Program
{
static void Main(string[] args)
{
test a = new test("Alice", 50000);
test b = new test("Bob", 10000);
Console.WriteLine("Before: a=" + a.getname());
Console.WriteLine("Before: b=" + b.getname());
swap(a, b);
Console.WriteLine("After: a=" + a.getname());
Console.WriteLine("After: b=" + b.getname());
Console.Read();
}
public static void swap(test x,test y)
{
test temp = x;
x = y;
y = temp;
Console.WriteLine("End of method: x=" + x.getname());
Console.WriteLine("End of method: y=" + y.getname());
}
}
class test
{
public test(String n, double s)
{
name = n;
salary = s;
}
public string getname()
{
return name;
}
public double getsalary()
{
return salary;
}
private string name;
private double salary;
}