C
C#2y 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
Angius2y ago
Make it not-void
Jimmacle
Jimmacle2y ago
$scope
MODiX
MODiX2y ago
you probably want $scopes
Jimmacle
Jimmacle2y ago
$scopes
MODiX
MODiX2y 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
MODiX2y 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
Angius2y ago
Here's how you can return a string from a method, for example
Ewan
EwanOP2y ago
oooooo ok thanks ill have a look

Did you find this page helpful?