How to Achieve Immutable DTOs With C#by@igorlopushko
2,756 reads
2,756 reads

How to Achieve Immutable DTOs With C#

by Igor Lopushko4mAugust 15th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In object-oriented and functional programming, an object cannot be modified after it is created. Immutable objects are also useful because they are inherently thread-safe. The question of whether or not DTOs should be immutable is a frequent question. Let’s dive in and see how immutability could be implemented with C#. We can move farther and use some syntactic sugar and use auto-properties to minimize the code. We create a simple object that represents a person and define a couple of properties.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How to Achieve Immutable DTOs With C#
Igor Lopushko HackerNoon profile picture
Igor Lopushko

Igor Lopushko

@igorlopushko

Programmer, Architect, Teacher

Learn More
LEARN MORE ABOUT @IGORLOPUSHKO'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Igor Lopushko HackerNoon profile picture
Igor Lopushko@igorlopushko
Programmer, Architect, Teacher

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite