Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Namespace ConsoleApplication8
{
Class Program
{
static void Main (string[] args)
{
int testnum = 100;
Operation (Testnum);
Screen output 100, indicating that the operation of the operation internal to Testnum does not affect the value of Testnum
Console.WriteLine ("Value of Testnum:" +testnum);
int num1=200;
otheropearation (ref NUM1);
//Screen output 10000, which indicates that the operation of otheropearation internal to NUM1 affects the NUM1 value. Same as reference type
console.writeline ("Num1 value:" +NUM1);
int num2;
To test the results yourself, the difference between ref and out I think is a need to initialize, one does not need.
Similar to these two methods you can use the ref and out modifier parameters to get the return value you want in case of void return type
Theotheroperation (out num2);
Console.WriteLine ("Value of num2:" +num2);
Console.readkey ();
}
static void theotheroperation (out int result)
{
Resul t = 25000;
}
static void otheropearation (ref int result)
& nbsp {
result = 1000 0;
}
static void operation (int result)
&NBS P {
result = $;
}
}
}
Use of ref and out in C #