Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
15 votes
2 answers
5k views

Why is casting a struct via Pointer slow, while Unsafe.As is fast?

Background I wanted to make a few integer-sized structs (i.e. 32 and 64 bits) that are easily convertible to/from primitive unmanaged types of the same size (i.e. Int32 and UInt32 for 32-bit-sized ...
Fit Dev's user avatar
  • 3,613
7 votes
2 answers
1k views

Why is it not possible to use both readonly and fixed-size buffers in structs in C# 7.2

With the release of C# 7.2 there is now the ability to have readonly structs, which in many cases can improve performance. For one of my structs I am using a fixed-size byte array to actually hold ...
Fit Dev's user avatar
  • 3,613