Hi,
I often have methods which are called regularly and have some "state" which has to be preserved between calls, as in:
float lastTime = 0.0f;
void Draw( float currentTime )
{
if( currentTime - lastTime > 0.5f )
{
// not enough FPS
}
lastTime = currentTime;
}
And it drives me nuts that the global "state" field (here "lastTime") is visible throughout the whole class while it is only needed in this one method. Is there any way to limit this global field's visibility scope to only the method or to make it local, but keep it's value between calls? The same question applies to fields used by Properties (which have some logic and can't be automatic).
Thanks in advance for any suggestion...