We dont know about the logic behind your code, seems lot of looping are there
the
return
keyword should be placed outside the loop since you are returning some value.
return the variable (res) at the last line of the function.
always follow this pattern
public ReturnType MyMethod()
{
ReturnType returnValue = default(ReturnType);
return returnValue;
}