0

我正在创建一个边框框,它应该在边框处创建一个具有不同颜色的框。这是我的代码:

class BorderedBox : ColoredBox
{
    public int heigth;
    public int width;

    ConsoleColor color = borderColor;

    public BorderedBox (Point p, int width, int height, ConsoleColor backColor, ConsoleColor borderColor)
        : base (p, width, height, backColor)
    {
            this.borderColor = borderColor;
    }
    public override void Draw()
    {
        for (int j = 0; j < height; j++)
        {
            Console.SetCursorPosition(p.X, p.Y + j);

            for (int i = 0; i < width; i++)
            {   
                if (i == 0 || i == width - 1 || j == 0 || j == height - 1)
                Console.BackgroundColor = borderColor;

                else 

                Console.BackgroundColor = backColor;

                Console.Write(' ');





            }
        }
    }
}

但是我在 [ ConsoleColor color = borderColor; ] ,它说“名称'borderColor'在当前上下文中不存在。有什么想法吗?

4

1 回答 1

5

在您尝试分配ConsoleColor color = borderColor时,borderColor尚未定义。我怀疑你刚刚搞砸了你的变量声明,真正的意思是:

ConsoleColor borderColor;

代替:

ConsoleColor color = borderColor;
于 2013-02-10T19:59:15.460 回答