Question: **Update:**

Again thanks for the examples, they have been very helpful and with the following, I don't mean
to take anything away from them.

Aren't the currently given examples, as far as I understand them & state-machines, only half of what we usually understand by a state-machine?  

In the sense that the examples do change state but that's only represented by changing the value of a variable (and allowing different value- changes in different states), while usually, a state machine should also change its behavior, and behavior not (only) in the sense of allowing different value changes for a variable depending on the state, but in the sense of allowing different methods to be executed for different states.

Or do I have a misconception of state machines and their common use?

---

**Original question:**

I found this discussion about [state machines & iterator blocks in c#](https://stackoverflow.com/questions/1406986/does-c-include-finite-state-machines) and tools to create state machines and whatnot for C#, so I found a lot of abstract stuff but as a noob, all of this is a little confusing.

So it would be great if someone could provide a C# source code-example that realizes a simple state machine with perhaps 3,4 states, just to get the gist of it.

Answer: 
What a bout StatePattern. Does that fit your needs?

I think its context related, but its worth a shot for sure.

<http://en.wikipedia.org/wiki/State_pattern>

This let your states decide where to go and not the "object" class.

Bruno
I too struggled with State Machines when used with a message broker like RabbitMQ or Rabbit.

I created this video to help others.

<https://www.youtube.com/watch?v=Vwfngk0YhLs&t=11s&ab_channel=GarryTaylor>

Code was from this Github repo

<https://github.com/welhell/masstransit-saga-example>