使用子句时何时使用 REF

来源:百度知道 编辑:UC知道 时间:2024/06/21 15:02:32
大家踊跃回答呵```

我理论比较差劲,不好专业给你说,
我一般使用ref的时候是想当调用方法的时候的参数,

被调用的方法里边处理完得出的结果,

想不用return的方法也可以更新相应的值的话就可以用ref

static void FillArray1(out int[] arr)
{
// Initialize the array:
arr = new int[5] { 1, 2, 3, 4, 5 };
}

static void Main2()
{
int[] theArray ; // Initialization is not required

// Pass the array to the callee using out:
FillArray1(out theArray);

// Display the array elements:
System.Console.WriteLine("Array elements are:");
for (int i = 0; i < theArray.Length; i++)
{
System.Console.Write(theArray[i] + " ");
}

// Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Con