布隆的C#方法组?

Mie*_*keB 2 c# methods

我已经创建了一些代码,但我找不到它的错误.这是代码:

    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;
    }
Run Code Online (Sandbox Code Playgroud)

我收到的错误消息:

无法将方法组'MyMethod'转换为非委托类型'bool'.你打算调用这个方法吗?

有人可以帮我解决这个问题吗?我似乎无法做到正确,我已经尝试了几件事......我也尝试将其更改为字符串并将返回值更改为字符串,但这会产生相同的错误(除了bool,它已更改为字符串) .提前致谢!

Tim*_*ter 9

MyMethod不是一个领域或财产,而是一种方法.必须使用()以下方法调用方法:

if (MyMethod()){ ... }
Run Code Online (Sandbox Code Playgroud)

你可以把它作为一个属性,然后你不需要它们,fe作为表达体:

public bool MyMethod => Form1.f >= 0.001;
Run Code Online (Sandbox Code Playgroud)

现在你可以使用(选择更有意义的名字):

if (MyMethod) { ... }
Run Code Online (Sandbox Code Playgroud)