not all code paths return a value

不羁岁月 提交于 2019-11-26 21:54:40

问题


I got this compiler error, what is the problem?

public PictureBox getinfo(int i, int j)
{
    return grid[i, j];
}

public  PictureBox kingmove(int i, int j)///<-----the problem is here
{
    getinfo(i, j);

    if (i < 9)
    {
        grid[i, j] = grid[i - 1, j - 1];
    }
    else
    {
        grid[i, j] = grid[i, j];
    }

回答1:


Your second method has no return statement but a return-type different from void.
Add a return statement at the end of the method and not in the beginning.

And you could have edited that into your previous question.

The way you mix UI and game-logic is ugly too. The game-logic should know nothing about WinForms, picture-boxes,...
Instead write a function which takes a gamestate and renders it into some control/bitmap/picturebox/...



来源:https://stackoverflow.com/questions/4292067/not-all-code-paths-return-a-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!