title: State Pattern C# with previous states
body: <p>I am new to the state pattern implementation in C#, could you provide some info on how you implement it.</p>
  
  <p>I am refactoring a state machine in C# using the state pattern. Currently my state machine contains 5 states and it is only possible to go forward or backward througout the states,i.e. from state 1 you need to go to state 2, 3 and 4 to finally arrive to state 5. <img src="https://i.stack.imgur.com/KJ2lV.jpg" alt="enter image description here"></p>
  
  <p>I am able to go forward just doing </p>
  
  <pre><code>       mainclass.State = new NextSate();
  </code></pre>
  
  <p>which creates a new state every time you want to go forward, however, once all of them have been created and/or you want to go backward I would need to go to the same states, not just a new one. How can I do that? Is there any better way to do it simple?</p>