-4

我知道这个问题以前在这里问过,但我找不到我的代码有什么问题。

      class Slider
     {
        public int const DEFAULT_SIZE = 20; // Problem is here. Invalid token in class 

    private int rise { get; set; }
    private int run { get; set; }
    private int size { get; set; }

    int positionX = 0;
    int positionY = 0;

    private int leftBoundX { get; set;}
    private int leftBoundY { get; set; }

    private int rightBoundX { get; set; }
    private int rightBoundY { get; set; }

    // Constructor
    Slider()
    {
        size = DEFAULT_SIZE; 
    }

    private void Bound()
    {
        if (positionX > leftBoundX)
            positionX = rightBoundX;
        else if (positionY > leftBoundY)
            positionY = rightBoundY;
        else if (positionX > leftBoundX)
            positionX = rightBoundX;
        else if (positionX > leftBoundX)
            positionX = rightBoundX;
        }

我用谷歌搜索了一些东西,他们告诉我要包括 System.Collection 我做了但仍然是同样的错误

4

1 回答 1

7

const修饰符必须在常量类型之前。你要:

public const int DEFAULT_SIZE = 20;

或者遵循 .NET 命名约定:

public const int DefaultSize = 20;
于 2012-10-17T18:45:26.370 回答