c# - StackOverFlow-Exception after changing value of Property -
i stackoverflow-exception when want change value of property "currentstate":
currentstate = state.quequed;
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
Post a Comment