Tuesday, March 13, 2012

switch statement

I have the following switch statement and am getting the error:
not all code paths return a value
I am not seeing why.

publicbool checkNewMove(ArrayList myArray,int myInt)

{

switch (myInt)

{

case 4 :

if( System.Convert.ToInt32( myArray[13] ) == 0 &&

System.Convert.ToInt32( myArrayMusic [8] ) == 1 )

{

myArrayMusic [8] = 0;

myArray[4] = 0;

myArray[13] = 1;

pNum = 4;

tempAL = myArray;

printArray(tempAL);

bSuccess =true;

break;

}

break;

default :

{

bSuccess =false;

//return bSuccess;

break;

}

//break;

}// end switch


}
Suggestions?
Thanks,
ZathI have added the line you are missing in red

publicbool checkNewMove(ArrayList myArray,int myInt)
{
switch (myInt)
{
case 4 :
if( System.Convert.ToInt32( myArray[13] ) == 0 &&
System.Convert.ToInt32( myArray[WhateverNumberThisIsSupposedToBe] ) == 1 )
{
myArray[WhateverNumberThisIsSupposedToBe] = 0;
myArray[4] = 0;
myArray[13] = 1;
pNum = 4;
tempAL = myArray;
printArray(tempAL);
bSuccess =true;
break;
}
break;
default :
{
bSuccess =false;
//return bSuccess;
break;
}
}// end switch
return bSuccess; [EDIT]
}


Thanks. don't know why I didn't see that. I have written many functions that need a return.
Must have been I was looking too hard at the switch.
Zath

0 comments:

Post a Comment