Create an event to watch for a change of variable

前端 未结 6 2071
抹茶落季
抹茶落季 2020-12-15 11:00

Let\'s just say that I have:

public Boolean booleanValue;

public bool someMethod(string value)
{
   // Do some work in here.
   return booleanValue = true;
         


        
6条回答
  •  遥遥无期
    2020-12-15 11:43

    CallingClass.BoolChangeEvent += new Action(AddressOfFunction);
    

    In your class with the bool property procedure:

    public event Action BoolChangeEvent;
    public Boolean booleanValue;
    public bool someMethod(string value)
    {
       // Raise event to signify the bool value has been set.
       BoolChangeEvent(value);
    
       // Do some work in here.
       booleanValue = true;
       return booleanValue;
    }
    

提交回复
热议问题