Is there a way to write a function that requires that who uses it to get the return value?
For example. this will be throw an error:
public int MustUseReturnValueFN() {
return 1;
}
private void main() {
MustUseReturnValueFN(); // Error
int a = MustUseReturnValueFN(); // Not Error
}
One way to "require" the caller to get a value would be to use out:
public void MustUseReturnValueFN(out int result)
{
result = 1;
}
static void Main()
{
int returnValue;
MustUseReturnValueFN(out returnValue);
Console.WriteLine(returnValue) // this will print '1' to the console
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With