KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'd like to use Lazy<T> to implement memoization but the initialization function appears to require a static context. For example, the following code refuses to compile, warning that non-static members a and b are inaccessible. It's not clear to me why this is so as the Lazy<int> object is an instance member itself and has no visibility in a static context. public class SomeExpensiveCalculation { private int a; private int b; public Lazy<int> Result = new Lazy<int>(() => a + b); //nope! }
Tags (comma-separated)
Save Edits
Cancel