I know how silly this may sound, but is there a way to attach an event to an integer?
For example, if you’re in a while loop and you do: i++; is it at all possible to do something like this?:
int i;
Form1_Load(object sender, EventArgs e)
{
i.MaximumNumberReached += new IntegerMaximumNumberReachedEventArgs();
}
while(x != y)
{
i++
}
private void MaximumNumberReached(object sender, EventAgrs e)
{
if(e.Value == 7)
{
this.Dispose(true);
}
}
Or should I just stop using my imagination so much?
Thank you
Firstly, no, you can’t do that. You could if, say, you had your own class representing numbers and overloaded relevant operators such that they initiated certain events, but you can’t invent events and attach them to existing classes (aside, say, from using an AOP framework and hooking into certain methods).
Secondly, no, don’t stop using your imagination. You may be interested in the following article: Arithmetic Overflow Checking.