© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
23 replies
MaggyD

Idiomatic C# Data Objects with Immutable Collections?

Hello, I'm trying to understand the best way to define a class that holds collection of some data that is completely immutable, yet serializable and deserilazable by System.Text.Json. For instance, I want this class to just represent a JSON document from the front-end application, it can be seen as a form of DTO as some sort. However, after spending 30 minutes online and asking ChatGPT, I feel like I still don't have a clear guide on how to construct a class with collections.

I have tried multiple things in my experience with C#.

Backing fields.
Just making them mutable and ignoring the warnings.
Some combination of the previous two???

Please help.

Thanks,
Maguire
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

When should we use immutable data structures?
C#CC# / help
4y ago
Collections
C#CC# / help
15mo ago
Updating Immutable object with ef
C#CC# / help
2y ago
✅ Immutable object with mutable clone
C#CC# / help
3y ago