2012-10-17 43 views
-3

我知道這個問題以前在這裏問過,但我無法找到我的代碼有什麼問題。類const const C中的令牌無效#

 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和我沒有,但還是同樣的錯誤

+1

請注意你已經嘗試和其中先前建議的方法失敗。 –

+0

你嘗試過[Google](http://bit.ly/QXiPOo)嗎? – Magnus

回答

7

const修改必須是恆定的之前類型。你想:

public const int DEFAULT_SIZE = 20; 

或者遵循.NET命名約定:

public const int DefaultSize = 20;