G
Guest
Hi, I need to return a value to a methods call from a switch statement nested
in the method. How can this be done?
int myMethod(int someValue)
{
switch (someValue)
{
case(1):
{
return anotherMethod()
}
case(2):
{
return somethingElse()
}
}
}
When I do this, I get a compile error saying, "not all code paths return a
value". I understand why I'm getting this as I'm not returning a value to the
main method. My question is, how do I return the value from the switch?
Thanks in advance
Ant
in the method. How can this be done?
int myMethod(int someValue)
{
switch (someValue)
{
case(1):
{
return anotherMethod()
}
case(2):
{
return somethingElse()
}
}
}
When I do this, I get a compile error saying, "not all code paths return a
value". I understand why I'm getting this as I'm not returning a value to the
main method. My question is, how do I return the value from the switch?
Thanks in advance
Ant