C
C#12mo ago
Ewan

✅ How to return variables from a function

void method() doesnt allow me to use the variables inside it outside the function, how do i do this?
8 Replies
Angius
Angius12mo ago
Make it not-void
Jimmacle
Jimmacle12mo ago
$scope
MODiX
MODiX12mo ago
you probably want $scopes
Jimmacle
Jimmacle12mo ago
$scopes
MODiX
MODiX12mo ago
scope A {
thing a;
scope B {
thing b;
}
}
scope A {
thing a;
scope B {
thing b;
}
}
thing a is available in scope A and scope B thing b is available only in scope B
MODiX
MODiX12mo ago
Angius
REPL Result: Success
string Method(int num)
{
return $"The number is {num}";
}

var str = Method(69);

Console.WriteLine(str);
string Method(int num)
{
return $"The number is {num}";
}

var str = Method(69);

Console.WriteLine(str);
Console Output
The number is 69
The number is 69
Compile: 594.482ms | Execution: 73.124ms | React with ❌ to remove this embed.
Angius
Angius12mo ago
Here's how you can return a string from a method, for example
Ewan
EwanOP12mo ago
oooooo ok thanks ill have a look
Want results from more Discord servers?
Add your server