1
bool connected = false;    

if (isConnected())  //if(isConnected() == true) also doesn't work
        {
          //code
        }
        else {
           connect();
        }

public bool isConnected() {
    if (nextEvent != "null" && !nextEvent.Contains(getEvent("disconnected"))) {
        connected = true;
    }
    return connected;
}

得到错误:

无法将方法组“isConnected”转换为非委托类型“bool”。

为什么?我已经查过了,在大多数情况下,人们忘记在函数名后面加上括号,如下所示:

if(isConnected) { // .... }

对我来说不是这样。怎么了?

4

1 回答 1

0

您可能正在尝试在其他函数中定义函数,如果将函数放在外部函数中,假设调用代码在内部YourFun()然后将isConnected()定义放在外部YourFun()

void YourFun()
{
    bool connected = false;    

    if (isConnected())  //if(isConnected() == true) also doesn't work
    {
          //code
    }
    else {
           connect();
    }
}

public bool isConnected() {
    if (nextEvent != "null" && !nextEvent.Contains(getEvent("disconnected"))) {
        connected = true;
    }
    return connected;
}
于 2013-07-25T11:51:44.150 回答