I would like to know how to set works in a property when it does more than just the value of a private member variable. Say I have a private member in my class ( private int myInt ).
For example, I can make sure the return value is not negative
get
{
if(myInt < 0)
myInt = 0;
return myInt;
}
With SET, all I can do is affect the private variable.
set { myInt = value; }
In any book, I have not seen how I can do more than that. How about if I do not do some operation before affecting the value of myInt? Let them say: If the value is negative, change the value 0 to myInt.
set
{
//Check if the value is non-negative, otherwise affect the 0 to myInt
}
thanks for the help
source
share