KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I would love to write code like this: class Zebra { public lazy int StripeCount { get { return ExpensiveCountingMethodThatReallyOnlyNeedsToBeRunOnce(); } } } EDIT: Why? I think it looks better than: class Zebra { private Lazy<int> _StripeCount; public Zebra() { this._StripeCount = new Lazy(() => ExpensiveCountingMethodThatReallyOnlyNeedsToBeRunOnce()); } public lazy int StripeCount { get { return this._StripeCount.Value; } } } The first time you call the property, it would run the code in the get block, and afterward would just return the value from it. My questions: What costs would be involved with adding this kind of keyword to the library? What situations would this be problematic in? Would you find this useful? I'm not starting a crusade to get this into the next version of the library, but I am curious what kind of considerations a feature such as this should have to go through.
Tags (comma-separated)
Save Edits
Cancel