For example:
private bool isThisADumbQuestion(bool trustMeThisWilLBeTrue)
{
if (trustMeThisWilLBeTrue)
return true;
}
This always gives the error that not all paths return a value. Is it possible in the function declaration to have it a return a default value in this case? Logically speaking:
private (bool = false) isThisADumbQuestion() {}
I’m guessing it’s not possible, but I’m still learning a lot of C# syntax so I thought I’d ask just in case. Seems like it’d be a useful bit of functionality to potentially save a lot of checking within the function body.
EDIT:
The above code is a logical example and not to be taken as an actual method. I edited it so that it will actually give the error promised. Sorry for the trouble, folks.
No this is not possible. All code paths on a non-void returning function must terminate with an explicit
returnorthrowstatement.Note: As xanatos pointed out there is an exception to the above rule for methods which the C# compiler can determine never terminate. For example