1
Answer

a simple traffic light

nas007bond

nas007bond

20y
5.8k
1
Dear all. This is simple, but I seem to be stuck. Imagin the following as "idealized language syntax" TYPE State { VARIANT Prepare_to_go, VARIANT go, VARIANT Prepare_to_stop, VARIANT stop } The above is (as you will have guessed) different states of a traffic light. My problem > How do you realize variants in c#? Ie Prepare_to_go is a State, so is "go", and so is "stop".. etc. they are all different states. When the above is coded in C#, and an object is created: for example State s = new State() Console.Write(s.state); // should print default "Stop", ie the object is initialized in "STOP" state when s.state = Prepare_to_go; Console.WriteLine(s.state); // should print the new state of the object. _________________________________________________________________________ My problem is about changing object states. Please give me guiudlines how to do this in c#. I have the following code: Class State { string state; public void setState(string _state) { state = _state; } ..... } etc.. BUT AS YOU CAN GUESS this is based on strings. The questions is about accomplishing variant states. Not using strings. I hope someone can guide me.
Answers (1)