I have a pseudo-realtime data processing application where I would like to use LazyInit<double> so I don’t do calculations I don’t need, but LazyInit<T> restricts T to classes. I can work around it, but I’d obviously prefer not to.
Does anybody know why this is?
The reason why is an underyling API choice in the LazyInit. It uses Interlocked.CompareExchange in order to do a thread safe value set. CompareExchange while generic is constrained to only use class types. Therefore the T value of LazyInit must also be a class.
You can view the implementation here: LazyInit