How do I automatically reset a boolean when any method other is called in C#?
Posted
by gtaborga
on Stack Overflow
See other posts from Stack Overflow
or by gtaborga
Published on 2010-04-12T23:03:41Z
Indexed on
2010/04/12
23:13 UTC
Read the original article
Hit count: 143
Hey everyone,
Using C#, I need to do some extra work if function A() was called right before function C(). If any other function was called in between A() and C() then I don't want to do that extra work. Any ideas that would require the least amount of code duplication?
I'm trying to avoid adding lines like "flag = false;" into every function B1..BN.
Here is a very basic example:
bool flag = false;
void A() { flag = true; }
void B1() { ... }
void B2() { ... }
void C() { if (flag) { //do something } }
The above example was just using a simple case but I'm open to using something other than booleans. The important thing is that I want to be able to set and reset a flag of sorts so that C() knows how to behave accordingly.
Thank you for your help. If you require clarification I will edit my post.
© Stack Overflow or respective owner