我知道此问题已在此处提出,但我无法找到我的代码有什么问题。
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;
}
我google了一些东西,他们告诉我要包含System.Collection我做了但仍然是同样的错误
答案 0 :(得分:7)
const
修饰符必须之前常量的类型。你想要:
public const int DEFAULT_SIZE = 20;
或遵循.NET命名约定:
public const int DefaultSize = 20;