C
C#7mo 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
Angius7mo ago
Make it not-void
Jimmacle
Jimmacle7mo ago
$scope
MODiX
MODiX7mo ago
you probably want $scopes
Jimmacle
Jimmacle7mo ago
$scopes
MODiX
MODiX7mo 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
MODiX7mo 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
Angius7mo ago
Here's how you can return a string from a method, for example
Ewan
Ewan7mo ago
oooooo ok thanks ill have a look