开发者

Using an If statement to determine if a method has been called

I need to figure out a way of using an if statement to determi开发者_Python百科ne whether a method in my code has been called, in order to perform an action. Is this possible in C#?


I'm not sure I understand the problem?

class MyClass {
  private bool m_myFunctionCalled = false;

  public void myFunction() {
    m_myFunctionCalled = true;
    return;
  }
}


public class MyClass
{
     private bool myFuncWasCalled = false;

     public void MyFunc()
     {
          myFuncWasCalled=true;      
     }

     public bool WasMyFuncCalled()
     {
        return myFuncWasCalled;
     }
     public void anotherFunc()
     {
          if(myFuncWasCalled)
          {
            // do some action
          }               
     }
}

See how to use it in this linqpad-programm

Using an If statement to determine if a method has been called


Yes, just make the method return something at the end.

For example:

...
bool temp = MyFunction();
if (temp == true) {
   // true was returned
}
...

bool MyFunction() {
   return true;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜