Windows Phone Developers

Tuesday, March 30, 2010

System.StackOverflowException was unhandled - Set Property C#

Set Property C# goes to infinite loop

If the set property goes to infinite loop, then there is some problem with accessor and mutator.

The following example is a good (rather bad) for recursive looping of the properties


public playerType PlayerType
{
get { return PlayerType; }

set
{
PlayerType = value;
}

}





In order to correct it, declare a private variable and get/set that variable.



private playerType _PlayerType;

public playerType PlayerType
{
get { return _PlayerType; }

set
{
_PlayerType = value;
}

}

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment