GrantPsych
New member
- Joined
- May 11, 2019
- Messages
- 3
- Programming Experience
- Beginner
Hello,
I am currently trying to learn C# by following this website https://csharp.net-tutorials.com/basics/function-parameters/
At the moment, I am stuck at that page trying to figure out the 'out' parameters.
This is the code example:
-----------------------------------------------------
static void Main(string[] args)
{
int number = 20;
AddFive(ref number);
Console.WriteLine(number);
Console.ReadKey();
}
static void AddFive(ref int number)
{
number = number + 5;
}
---------------------------------------------------------
This is the excerpt from the tutorial:
'Using the out modifier is just like using the ref modifier, as shown above. Simply change the ref keyword to the out keyword. In the example above, also remember to remove the value assigned to number in the method and declare it in the call function instead.'
I am having difficulty understanding what the exercept mean by 'remove the value assigned to number and declare it in the call function.
I switched the 'ref' to 'out' but instantly felt lost as to the next step. Thank you in advance!
I am currently trying to learn C# by following this website https://csharp.net-tutorials.com/basics/function-parameters/
At the moment, I am stuck at that page trying to figure out the 'out' parameters.
This is the code example:
-----------------------------------------------------
static void Main(string[] args)
{
int number = 20;
AddFive(ref number);
Console.WriteLine(number);
Console.ReadKey();
}
static void AddFive(ref int number)
{
number = number + 5;
}
---------------------------------------------------------
This is the excerpt from the tutorial:
'Using the out modifier is just like using the ref modifier, as shown above. Simply change the ref keyword to the out keyword. In the example above, also remember to remove the value assigned to number in the method and declare it in the call function instead.'
I am having difficulty understanding what the exercept mean by 'remove the value assigned to number and declare it in the call function.
I switched the 'ref' to 'out' but instantly felt lost as to the next step. Thank you in advance!