I have created some code, but I can't find what's wrong with it. Here's the code:
private void timer1_Tick(object sender, EventArgs e)
{
if (MyMethod) //<==underlines this and gives the error
{
//code
}
else
{
//code
}
}
public bool MyMethod()
{
if (Form1.f >= 0.001)
return true;
else
return false;
}
The error message I get:
Cannot convert method group 'MyMethod' to non-delegate type 'bool'. Did you intend to invoke the method?
Can someone help me with this problem? I can't seem to get it right, I've tried several things... I have also tried to change it to string and the return values to strings but that gives the same error (except the bool, that's changed into string). Thanks in advance!
MyMethod is not a field or property but a method. A method must be called with ():
if (MyMethod()){ ... }
You could make it a property, then you don't need them, f.e. as expression-body:
public bool MyMethod => Form1.f >= 0.001;
Now you can use (choose more meaningful names):
if (MyMethod) { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With