Unsafe.As
vs Unsafe.BitCast
#104626
-
What's the difference between |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It also helps guarantee correctness as it also requires the input/output be the same size and therefore that you aren't accessing bits that don't exist. |
Beta Was this translation helpful? Give feedback.
Unsafe.BitCast
works on value types and doesn't require taking an address, which can improve the overall codegen/perf in some complex scenarios (in simple ones the JIT will normally recognize its not actually "address-taken").It also helps guarantee correctness as it also requires the input/output be the same size and therefore that you aren't accessing bits that don't exist.