C
C#12mo ago
Ewan

What is going wrong with this else inside a method here?

What is going wrong with this else inside a method here?
No description
No description
9 Replies
Sossenbinder
Sossenbinder12mo ago
Your if ends with a semicolon
Jimmacle
Jimmacle12mo ago
i was gonna make him hunt for it, but yes
Ewan
EwanOP12mo ago
oh i didnt even know that was a thing thank you haha
Sossenbinder
Sossenbinder12mo ago
Oh, I ruined catfine
Jimmacle
Jimmacle12mo ago
but yeah, what happens is that now you have an if statement with nothing in it because the semicolon ends it
Ewan
EwanOP12mo ago
i have another question? in my code u can see that in the if statement i have to return 0 cause all paths have to return something. is there a way to return nothing in one path and have the other path return something instead?
Jimmacle
Jimmacle12mo ago
no, if your method returns something it has to return something no matter what the only other option is to throw an exception which you should only do if something unrecoverable happened
Ewan
EwanOP12mo ago
ooo ok thank you, im just used to python is all gotcha thanks!!
Jimmacle
Jimmacle12mo ago
the closest thing to making it return "nothing" would be to make the return type int? which would let you return null which might be what you need depending on what meanings you need the return value to have
Want results from more Discord servers?
Add your server