Is there a special method that you can add if you get an i++ type of operation on a property?
Here is an example of what I’m trying to do. I know this don’t work, but this gives you an idea of what I’m talking about. Actually, I’m working with two internals and I want to increase one on + and the other on -.
int mynum;
int yournum
{
get{ return mynum; }
set{ mynum = value; }
set++{ mynum = mynum + 5; return mynum; } //this is what I want to do
}
// elsewhere in the program
yournum++; //increases by 5
It sounds like you want to override the behavior which occurs when
++is invoked on the propertyyournum. If so that’s not possible in C# for exactly the code you outlined in your sample. The++operator should be incrementing by1and every user callingyournum++would expect that behavior. To change it silently to5would certainly lead to user confusionIt would be possible to get similar behavior by defining a type with a custom
++operator which did the+ 5conversion instead of+1. For exampleIf you now defined
yournameto beStrangeIntthen you would get the behavior you were looking for