public int Position
{
get
{
if (Session["Position"] != null)
{
Position = Convert.ToInt32(Session["Position"]);
}
else
{
Position = 5;
}
return Position;
}
set
{
Position = value;
}
}
my program calls the get and goes into if loop and then runs infitely into set code
The error is because in your set {}
you are invoking the same setter recursively.
Correct code would be
private int _position;
public int Position
{
get
{
if (Session["Position"] != null)
{
this._position = Convert.ToInt32(Session["Position"]);
}
else
{
this._position = 5;
}
return this._position;
}
set
{
this._position = value;
}
}
Use a member variable or perhaps store it in the session.
private int _position;
public int Position
{
get
{
if (Session["Position"] != null)
{
_position= Convert.ToInt32(Session["Position"]);
}
else
{
_position= 5;
}
return _position;
}
set
{
_position = value;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With