您的位置:首页 > 其它

让你更好的理解 引用传递 和值传递

2012-01-10 14:17 169 查看
using System;

public
classTest1

{

public
static
voidMain()

{

int num =
0;

Person p = new Person("Li");

A1(p, num);

Console.WriteLine("{0},{1}", p.name,num);

}

static
void A1(Person
x,
intnum)

{

x =
new Person("Wang");

num = 1;

}

}

public
classPerson

{

public
stringname;

public Person(stringname)

{

this.name =name;

}

}

问题是最后输出结果是什么?
答案就放在第一个回复吧!
和这个比较一下会让你明朗一些。
static void A1(Person x, intnum)

{

x.name="wang";

num = 1;

}

这是原帖地址,可以看看评论来理解一下。
http://topic.csdn.net/u/20090402/14/1127eb2a-3693-4d2c-8705-18c08e216177.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: