Hi, so I have watched videos and read posts about return in c# but I still just don’t understand what it does. If you guys could help explain it to me that would be great, thanks!
So, return in C#… It returns a value, or it gets out of a function.
So, return on a value, for example:
int MyCustomINTFunction()
{
return 10;
}
int MyValue = 0;
MyValue = MyCustomINTFunction(); //Would return 10.
now, return in a regular function will just ‘exit’ that function,
so like:
void MyComplicatedCode()
{
if (this != that) return;
SuperRandomLongComplicatedCodeHereThatTakesUpAlotOrAlittleProcessingPower;
}
In that example, if this does not equal that, then we don’t actually need to run the rest of the code, so we can ‘return’ or get OUT of that function. Once return is called, it will exit the code, therefore the ‘SuperRandomLong…blah blah’ would not actually get called.