-7

我正在尝试创建可以快速运行的代码。为此,我在需要时跳过了一些变量初始化。例如:(我不能更改标签\goto 部分,我必须在这种情况下使用它)

bool Func(bool BooleanParameter) {
    if (BooleanParameter)
        goto _true;
    else
        goto _false;
_true:
    string str; //Some code after that one that does with this variable
    return false;
_false:
    return true; //Exception because str doesn't initialized
}

但是有一个例外,因为有一种方法可以不初始化变量并且变量最终会破坏。

4

2 回答 2

6

为什么不只是:

bool Func(bool booleanParameter)
{
    if (booleanParameter)
    {
        string str;
        // ...
        return false;
    }
    return true;
}

?

这似乎可以达到预期的结果,而无需怀疑使用goto等。

于 2012-07-29T13:44:51.887 回答
1

尝试像这样确定字符串的范围

_true:
  {
  string str;
  return false;
  }
于 2012-07-29T13:42:43.020 回答