After the user is done with form "f", the form will retain a value that I want to check before running doStuff(). Like, if f.value > 0 , then run doStuff(), else, don't run doStuff(). How can I most concisely modify my code to allow for this check? I don't quite understand when the delegate is assigned, if I pass f.value, will it take the value when I'm adding the delegate, or when it is running the delegate?
form f = new form();
f.Show();
f.FormClosing += delegate{doStuff();};
Thanks!
You can capture the value of the reference when making the delegate:
f.FormClosing += delegate { if(f.value > 0) doStuff(); };
When the event occurs, it will check the current value of the captured reference f, and if the condition matches, continue executing.
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