C
C#14mo ago
Sir_Crusader

Using Out parameter

I might be dumb but I can't wrap my head around the Out parameter in self defined methods. Is Out used to create a boolean value? When do I call upon it and why? I was cruising through the course but I just don't understand this parameter, while I think it's probably not even that difficult. :P I asked ChatGPT to explain it to me like I'm 12 and I still didn't get it! Just made it work after a lot of trial and error in CodeAcademy but honestly barely knew what I was doing with it and why. See code for reference! Can someone maybe help me grasp it a bit better? :)
No description
6 Replies
Sir_Crusader
Sir_CrusaderOP14mo ago
Just noticed that my code didn't even apply the method that I've created, here is the corrected version for reference. :
No description
Cattywampus
Cattywampus14mo ago
you printed the string not the out var
MODiX
MODiX14mo ago
Compile C# code in #bot-spam, use !eval Example:
!eval for(int i = 0; i < 4; i++) Console.WriteLine(i);
!eval for(int i = 0; i < 4; i++) Console.WriteLine(i);
MODiX
MODiX14mo ago
SlimStv
REPL Result: Success
bool TestOut(int input, out int numba)
{
numba = input;
return input > 1;
}

Console.WriteLine("result is : " + TestOut(2, out var nombre) + " number is : " + nombre);
bool TestOut(int input, out int numba)
{
numba = input;
return input > 1;
}

Console.WriteLine("result is : " + TestOut(2, out var nombre) + " number is : " + nombre);
Console Output
result is : True number is : 2
result is : True number is : 2
Compile: 465.638ms | Execution: 33.264ms | React with ❌ to remove this embed.
Sir_Crusader
Sir_CrusaderOP14mo ago
Yess, thankyou. That's a good example. :)
Cattywampus
Cattywampus14mo ago
aight goodluck!

Did you find this page helpful?