How does SET works with property in C#?
- by Richard77
Hello,
I'd like to know how set works in a property when it does more than just setting the value of a private member variable. Let's say I've a private member in my class (private int myInt).
For instance, I can make sure that the the value returned is not negative
get
{
if(myInt < 0)
myInt = 0;
return myInt;
}
With SET, all I can do is affecting the private variable like so
set { myInt = value; }
I didn't see in any book how I can do more than that. How about if I wan't to do some operation before affecting the value to myInt? Let's say: If the value is negative, affect 0 to myInt.
set
{
//Check if the value is non-negative, otherwise affect the 0 to myInt
}
Thanks for helping