4 ms·
> C# does not have anything even remotely like records (structs are value types, and properties are fields) so what's your point? How would you compare records
by GordonS 7y ago
> C# does not have anything even remotely like records (structs are value types, and properties are fields) so what's your point?
How would you compare records to c# language features then? Are records value or ref types? Do they live in the stack or the heap?
- anthonybsd 7y agoReference; heap; They are data containers, not control structures.
- GordonS 7y agoCan't you use structs in C# as data containers?
- anthonybsd 7y agoUghh, you can provided that they are 1) Small 2) Short lived. Because they live on the stack and follow the rules of value types you really shouldn't be using them for anything major. I.e. you want to model a SQL query result for a table with more than 3 columns? Probably struct is NOT the way to go, use a POCO class.
- GordonS 7y agoC# structs don't always live on the stack (unless you use a ref struct)[0] [0] https://kalapos.net/Blog/ShowPost/DotNetConceptOfTheWeek16-RefStruct https://kalapos.net/Blog/ShowPost/DotNetConceptOfTheWeek16-R...
- anthonybsd 7y agoWell of course. Just like an int doesn't always live on the stuck. I.e. when it's declared as a field for example. If you are piping data from SQL DB into a List<YourStruct> the list is a reference type and will of course be on the heap. Another issue with struct being big is really when it's being passed around and value copying starts to occur. You want to minimize this if the struct is large. My point being is that if in doubt, you probably don't want to use a struct and hence it's not a general purpose data container.