12 ms·
C# had value types from day one.
by h4b4n3r0 8y ago
C# had value types from day one.
- __abc 8y agoAnd ....
- slavapestov 8y agoYeah, its one of the few that does. Even then, C# value types are immutable, and there are no value type collections (not a collection of value types, but a collection that is itself a value type). The lack of these two features means it’s not as generally useful as you might like.
- h4b4n3r0 8y agoAn array of value types (including structs) in .NET (not just C#) is laid out contiguously in memory and stored in-place like an array of C/C++ structs would be. The problem of chasing pointers does not exist if you use structs (and don't use non-value types such as strings within those structs). And .NET value types are mutable, of course.
- slavapestov 8y agoRight, but the array itself has reference semantics.
- pjmlp 8y agoNot when you allocate it on the stack via stackalloc, as of C# 7 also allowed in safe code.