Out and ref
1 out and ref the address of the variable (reference address), formal parameter changes, the actual parameters also change. Because they all refer to an address;
2 parameters with ref and out adornments can only pass variables that cannot pass constants.
3 The difference between out and ref
The out-decorated parameters must be modified in the method, and ref can be modified or not modified;
Out in the incoming parameter, the parameter is a local variable, you can not assign a value, because out must be assigned to the value;
A ref-decorated parameter must have an initial value in the argument before it can be invoked. It is not necessarily assigned a value because ref is decorated.
Code on:
Class Program {static void Main (string[] args) {int[] Zs = {3, 13, 6, 45, 6, 7, 99, 1
79};
The difference, using ref-decorated parameters, must be assigned the initial value before use; int min=0, Max;
When calling a method, also add ref and Max Getminandmax (Zs,ref min,out max);
Console.WriteLine ("The largest value in this array is {0}, the minimum value is {1}", max,min);
Console.readkey ();
#region out parameter to find the maximum and minimum static void Getminandmax (int[] nums in the array, ref int min, out int max)
{///incoming array is empty, returns 0 if (Nums = null) {min = 0;
max = 0;
Return
//Bubble Sort: Interview with,//actual development: Array.Sort (Nums); for (int i = 0; i < Nums. Length-1; i++) {for (int j = 0; J < Nums. Length-1-I; J + +) {if (Nums[j] > nums[j + 1]) {int
temp = Nums[j]; NUMS[J] = nums[j + 1];
Nums[j + 1] = temp;
()}//Find two min = nums[0]; max = Nums[nums.
LENGTH-1]; } #endregion}