获取错误"Cannot convert to null 'Point' because it is a non-nullable value type."



对不起,这么简单的问题(我已经用谷歌搜索过,但我被难住了,编程新手(

下面的示例代码

  public Point GetRandomWalkableLocationInRoom(Rectangle room)
    {
        if (DoesRoomHaveWalkableSpace(room))
        {
            for (int i = 0; i < 100; i++)
            {
                int x = Game.Random.Next(1, room.Width - 2) + room.X;
                int y = Game.Random.Next(1, room.Height - 2) + room.Y;
                if (IsWalkable(x, y))
                {
                    return new Point(x, y);
                }
            }
        }

        return null;
    }

在 DoesRoomHaveWalkableSpace(room( 为 false 的情况下,要么抛出异常(如果这符合你的实现(,要么返回一些默认值,比如 'new Point(double.纳N,双倍。NaN("或"新点(空,空("。

最新更新