Replies: 2 comments 6 replies
-
I don't think so. Method call can have side effects (such as |
Beta Was this translation helpful? Give feedback.
-
Maybe we can add a void MyMethod()
{
var CachedValue = GetValue(0);
this.a = CachedValue * 0.5;
this.b = CachedValue * 0.6;
//Instead of
//this.a = GetValue(0) * 0.5;
//this.b = GetValue(0) * 0.6;
} and with the stale keyword added this function body : void stale MyMethod()
{
this.a = GetValue(0) * 0.5;
this.b = GetValue(0) * 0.6;
} Would be equivalent to the method above. internal Layout SomeLayout => GetValue(0);
internal stale Layout MyVariable => SomeLayout with { height = SomeLayout.height*0.5, width = SomeLayout.width*0.6}; |
Beta Was this translation helpful? Give feedback.
-
I was looking at this code in my program
and I was wondering if .NET can cache some of the values instead of calling the method represented by the expression body definition (=> operator) thus wasting computation resources
Beta Was this translation helpful? Give feedback.
All reactions