2013-12-19 2 views
0

여러 상태가있는 클래스 개체를 만들고 싶습니다. 각 개체는 매번 하나씩 만 활성화 될 수 있습니다. 그래서 예를 들면 :여러 조건을 사용하여 개체를 만드는 방법

Plane boeing747 = new Plane; 

boeing747.State = flying 

또는

boeing747.State.flying = true; 

if(boeing747.State.flying == true); 
    console.writeline("it flyes"); 
else if(boeing747.State.driving == true) 
    console.writeline("it drives"); 
else 
    console.writeline("nothing goes"); 
// console reads: "it flyes" 

boeing747.State.driving = true; 
if(boeing747.State.flying == true); 
    console.writeline("it flyes"); 
else if(boeing747.State.driving == true) 
    console.writeline("it drives"); 
else 
    console.writeline("nothing goes"); 
// console reads: "it drives" 

답변

6

당신은 사용할 수 있습니다 :이 같은 조건을 ADRESS 좋아 운전, 비행,

서 :

클래스 비행기는 세 가지 조건이있다 이에 대한 열거 형 :

public enum PlaneState 
{ 
    Flying, 
    Driving, 
    Standing, 
} 

이며 수업 중 :

public PlaneState State 
{ 
    get; 
    set; 
} 
관련 문제