并非所有的代码路径返回值 [英] not all code paths return a value

查看:91
本文介绍了并非所有的代码路径返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个编译器错误,问题是什么?



 公开的PictureBox是getinfo(INT I,诠释J)
{
返回电网[I,J]。
}

公众的PictureBox kingmove(INT I,诠释J)///< -----的问题是在这里
{
是getinfo(I, j)条;

如果(I< 9)
{
电网[I,J] =网[我 - 1,J - 1];
}
,否则
{
电网[I,J] =电网[I,J]。
}


解决方案

你的第二个方法没有任何收益语句但是从无效

添加<$ C $返回值类型不同C>收益的方法,而不是在开始的结束的声明。



和你可能会编辑那到你前面的问题。



在混合UI和游戏逻辑的方式是丑陋了。游戏逻辑应该一无所知的WinForms,子母箱,...

而是写一个函数,它接受一个游戏状态和它呈现为一定的控制/位图/ PictureBox的/...


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.
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/...

这篇关于并非所有的代码路径返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆