c# - StackOverFlow-Exception after changing value of Property -


i stackoverflow-exception when want change value of property "currentstate":

currentstate = state.quequed; 

enter image description here

this simple logical error , problem of "infinite recursion" because currentstate property attempting set itself. solution simple.

currently have (simplified)

public state currentstate {     set {         // ...          currentstate = state.whatever;          // ...     }     {         return ???; /// ??? => don't know you're returning?     } } 

solution: create backing field property doesn't call itself.

private state _currentstate;  public state currentstate {     set {         // ...          // illustration purposes. you'd checking          // or assigning value of "value" parameter, not          // setting same value suggests.         _currentstate = state.whatever;          // ...     }     {         return _currentstate;     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -