本帖最后由 郑丹丹1990 于 2013-4-24 08:56 编辑
public class Starter {
public static void MethodA(XInt alias) {
XInt inner = new XInt();
inner.iField = 5;
alias = inner;
}
public static void MethodB(int paremeter) {
paremeter += 5;
}
public static void MethodC(ref int i) {
i += 5;
}
public static void MethodD(XInt xint){
xint.iField += 5;
}
public static void Main() {
XInt obj = new XInt();
MethodA(obj);
Console.WriteLine("引用传值{0}",obj.iField);//2为何是2?????
int local = 2;
MethodB(local);
Console.WriteLine("值传递{0}",local);//2
int var = 2;
MethodC(ref var);
Console.WriteLine("引用传值{0}", var);//7
XInt xint = new XInt();
MethodD(xint);
Console.WriteLine("引用传值{0}", xint.iField);//7
Console.ReadKey();
}
|