求助,请高人指点!!!
using System;
class nbr { public double square ( ref double x) { x = x * x; return x; } } class TestApp { public static void Main() { nbr doit = new nbr();
double nbr1 = 3; double retVal = 0;
Console.WriteLine("Before square -> nbre1 = {0},retVal = {1}",nbr1 , retVal);
retVal = doit.square( ref nbr1 );
Console.WriteLine("After square -> nbre1 = {0},retVal = {1}",nbr1 , retVal); } } 以上小程序关于ref参数的,输出结果: Before square -> nbre1 = 3,retVal = 0 After square -> nbre1 = 9,retVal = 9 我想问一下高人,为什么输出结果的第二行是nbre1 = 9呢,请解释一下,在没有ref修饰,第二行结果是3和9。