2 ms·
This is not entirely true as of C# 7.2. That version of the language adds "ref structs" - which can only be allocated on the stack and cannot be boxed [1]. Thi
by clix11 7y ago
This is not entirely true as of C# 7.2. That version of the language adds "ref structs" - which can only be allocated on the stack and cannot be boxed [1].
This requires some care though, as the struct may still be copied needlessly if it is not also marked as `readonly` [2].
[1] - https://blogs.msdn.microsoft.com/mazhou/2018/03/02/c-7-series-part-9-ref-structs/ https://blogs.msdn.microsoft.com/mazhou/2018/03/02/c-7-serie...
[2] - https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-ef...