I want to exchange two nullable decimal values, like this:
o2 = Interlocked.Exchange(ref o1, o2);
The type 'decimal?' must be a reference type in order to use it as parameter 'T' in the generic type or method 'System.Threading.Interlocked.Exchange(ref T, T)'.
Is there better idea than this:
decimal? temp = o1;
o1 = o2;
o2 = temp;
Thanks in advance!
Two thoughts:
object and cast at the consumerBox<T> class where T:struct (and make it immutable), and swap some Box<decimal> referencesIn both cases, the consumer should take a clone of the value before anything else (no double reads; it may change between reads).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With