I have code like this:
public class SomeClass
{
private bool Flag;
public void OnBar() //this is called from DoSomething();
{
if (Flag) //For some reason Flag=false
}
public void OnFoo() //this is called from some anonymous method (not mine)
{
Flag = true;
DoSomething();
}
}
The Callstack looks like this:
AnonymousMethod();
OnFoo();
DoSomething();
OnBar();
I have read MSDN article about outer variables with anonymous methods but they apply to local variables, what about class level variables.
Why Flag is false inside OnBar() method, and how to solve this problem.
That definitively has nothing to do with anonymous methods. It must be something that happens inside
DoSomething.There are basically two possibilities:
1) Flag is re-set in
DoSomething:2)
DoSomethingcreates a new instance ofSomeClassand callsOnBaron that: