2012-10-17 5 views
-3

이 질문은 이전에 여기에서 물었지만 내 코드에 무엇이 잘못되었는지는 알 수 없습니다. 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; 
     } 

나는 그들이 System.Collection을 포함하라고 내가했지만 여전히 같은 오류

+1

이전에 제안 된 방법이 실패하여 위치를 시도하고 무엇을주의하세요. –

+0

[Google] (http://bit.ly/QXiPOo) 문제를 사용해 보셨나요? – Magnus

답변

7

const 수정 상수의 전에 유형이어야한다, 물건을 봤. 당신이 원하는 :

public const int DEFAULT_SIZE = 20; 

또는 따르지 .NET 명명 규칙 :

public const int DefaultSize = 20; 
관련 문제