C
C#2y ago
Gladiator

❔ Should dictionary values be value types (struct)

To store data container (just data), do you prefer to define dictionary values as value types (struct) or class?
9 Replies
Thinker
Thinker2y ago
Depends on what kind of data it is If it's just purely immutable data, then I'd personally go for record structs.
Gladiator
GladiatorOP2y ago
Changing data when it is reference type, reflects changes, is it OK generally?
Thinker
Thinker2y ago
Depends on what you want. Personally I try to embrace immutability as much as possible, because it generally makes things more predictable and easier to debug.
Gladiator
GladiatorOP2y ago
My confusion is I should track it reflects or not. It is struct or class, then if it is class type, they create it and then pass to another class or not. Because it is not my code, I have to move to other classes back and forth to understand it Suppose dictionary values is about sotck Dictionary key is product type and value is stock data Stock data contains available count and reserved count. I agree it is better to define it as struct (immutable)
333fred
333fred2y ago
As always, $itdepends
333fred
333fred2y ago
If it's a decent size, it can be better to define it as a class
Gladiator
GladiatorOP2y ago
I exactly said what stock data contains Product type, int available, int reserved. OK, appreciated
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server