properties - C# - Is storing a property's value to a variable for faster access later a good idea? -


i have read-only property use in computations, example:

//property public decimal magicnumber {     => return getnumberaftercomputations(); }  //in calling method label1.text = "total: " + (this.magicnumber / this.magicnumber * 0.5m).tostring(); label2.text = "another total: " + (this.magicnumber - 0.12837m).tostring(); 

considering getnumberaftercomputations() has complex computations, storing magicnumber temporary variable speed things up, said method won't run every access property? this:

//in calling method decimal _magicnumber = this.magicnumber; label1.text = "total: " + (_magicnumber / _magicnumber * 0.5m).tostring(); label2.text = "another total: " + (_magicnumber - 0.12837m).tostring(); 


Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -