I recently started using Lazy throughout my application, and I was wondering if there are any obvious negative aspects that I need to take into account when using Lazy<
What exactly do you mean with "throughout my application"?
I think it should only be used when you're not sure if the value will be used or not, which may only be the case with optional parameters that take a long time to compute. This could include complex calculations, file-handling, Webservices, database access and so on.
On the other hand, why use Lazy
here? In most cases you can simply call a method instead of lazy.Value
and it makes no difference anyway. BUT it's more simple and obvious to the programmer what's happening in this situation without Lazy
.
One obvious upside may be already implemented caching of the value, but I don't think this is such a big advantage.