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
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;
}
精彩评论