Skip to content

Stateless vs Stateful classes in C# #179

Answered by christiannagel
ShervanN asked this question in Q&A
Discussion options

You must be logged in to vote

With a stateful class you can set and change state, e.g. a Person class with a FirstName property with get and set accessor. The values can change.

With a stateless type you can't change the state.

In case multiple threads access the same stateful object instance, you need to synchronize the access from threads, otherwise you can get race conditions.

If you use an object that can't change the state and access it from multiple threads, you will have less issues.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ShervanN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants