例如,
class Age
{
public int Year
{
get;
set;
}
public Age(int year)
{
Year = year;
}
}
class Person
{
public Age MyAge
{
get;
set;
}
public Person(Age age)
{
age.Year = ( age.Year * 2 );
MyAge = age;
}
}
[客户]
Age a = new Age(10);
Person p = new Person( a );
构造新Age
类时,Year
属性为:10。但是,Person 类将 Year 更改为 20,即使没有 ref 关键字...
有人可以解释为什么 Year 还不是 10 吗?