获得CS1513}预期,但所有大括号都在那里

时间:2014-02-19 00:57:57

标签: c#

我是一名新手程序员,请原谅我,如果这是显而易见的事情。我检查了所有的大括号,并在这里查找所有情况下的匹配对。没有这个代码片段,代码编译得很好。有任何想法吗?

protected bool Bullish(int ConsecutiveBullishBars)
    { 
       private int howmanybars = ConsecutiveBullishBars - 1;
       private bool IsMarketBullish = false;

        while (howmanybars >= 0) 
        {
            if (Close[howmanybars] > KeltnerChannel(Offset, Period)[howmanybars])
            {
                IsMarketBullish = true;
            }

            else
            {
                IsMarketBullish = false;
            }
            howmanybars--;
        }

        return IsMarketBullish;
    }

以下是完整代码:http://pastebin.com/aHbzqKbw

1 个答案:

答案 0 :(得分:3)

将本地方法变量标记为private没有任何意义。这就是造成错误的原因。

为什么编译器会给你}预期的错误,我不确定。我猜测编译器假设private int howmanybars被解释为私有实例字段定义,不能在方法内声明。所以它告诉你它希望Bullish方法在声明之前结束。

protected bool Bullish(int ConsecutiveBullishBars)
{ 
   int howmanybars = ConsecutiveBullishBars - 1;
   bool IsMarketBullish = false;

    while (howmanybars >= 0) 
    {
        if (Close[howmanybars] > KeltnerChannel(Offset, Period)[howmanybars])
        {
            IsMarketBullish = true;
        }
        else
        {
            IsMarketBullish = false;
        }
        howmanybars--;
    }

    return IsMarketBullish;
}