本帖最后由 崔增阳 于 2014-3-28 21:07 编辑
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Person(string name, int age)
{
Name = name;
Age = age;
}
public Person(){}
public void Display()
{
Console.WriteLine("Name: {0}, Age: {1}",Name,Age);
}
}
internal class Program
{
private static void Main(string[] args)
{
Person mel=new Person("Mel",23);
Console.WriteLine("Before by ref call, Person is:");
mel.Display();
SendAPersonByReference(ref mel);
Console.WriteLine("After by ref call, Person is:");
mel.Display();
Console.ReadKey();
}
static void SendAPersonByReference(ref Person p)
{
p.Age = 555;
p=new Person("Nikki",999);
}
}
程序输出是:
Before by ref call, Person is:
Name: Mel, Age: 23
After by ref call, Person is:
Name: Nikki, Age: 999
谁能帮我解释一下程序输出?
|
|