❔ 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
Depends on what kind of data it is
If it's just purely immutable data, then I'd personally go for record structs.
Changing data when it is reference type, reflects changes, is it OK generally?
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.
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)
As always, $itdepends
If it's a decent size, it can be better to define it as a class
I exactly said what stock data contains
Product type, int available, int reserved.
OK, appreciated
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.