通过引用传递引用对象怎么可能有用。常规用法如下:
public static void main()
{
Student st = new Student();
st.FirstName = "Marc";
PutLastName(st);
Console.WriteLLine(st.FirstName + " " + st.LastName);
}
public static PutLastName(Student student)
{
student.LastName = "Anthony";
}
为什么有人会写以下内容,它做同样的事情并打印:“Marc Anthony”:
public static void main()
{
Student st = new Student();
st.FirstName = "Marc";
PutLastName(ref st);
Console.WriteLLine(st.FirstName + " " + st.LastName);
}
public static PutLastName(ref Student student)
{
student.LastName = "Anthony";
}