C
C#7mo 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
Sossenbinder7mo ago
Your if ends with a semicolon
Jimmacle
Jimmacle7mo ago
i was gonna make him hunt for it, but yes
Ewan
Ewan7mo ago
oh i didnt even know that was a thing thank you haha
Sossenbinder
Sossenbinder7mo ago
Oh, I ruined catfine
Jimmacle
Jimmacle7mo ago
but yeah, what happens is that now you have an if statement with nothing in it because the semicolon ends it
Ewan
Ewan7mo 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
Jimmacle7mo 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
Ewan7mo ago
ooo ok thank you, im just used to python is all gotcha thanks!!
Jimmacle
Jimmacle7mo 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