简体   繁体   English

并非所有代码路径都返回一个值

[英]not all code paths return a value

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];
    }

Your second method has no return statement but a return-type different from void . 你的第二个方法没有return语句,但返回类型不同于void
Add a return statement at the end of the method and not in the beginning. 在方法的末尾添加一个return语句,而不是在开头。

And you could have edited that into your previous question. 你可以把它编辑成你以前的问题。

The way you mix UI and game-logic is ugly too. 混合UI和游戏逻辑的方式也很难看。 The game-logic should know nothing about WinForms, picture-boxes,... 游戏逻辑应该对WinForms,图片框,......一无所知。
Instead write a function which takes a gamestate and renders it into some control/bitmap/picturebox/... 而是编写一个函数,它将游戏状态转换为某个控件/位图/图片框/ ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM