C# 无效令牌';返回';类、结构或接口成员声明中的

C# 无效令牌';返回';类、结构或接口成员声明中的,c#,C#,正在给予: return found; 代码: public bool IsTextPresent(ISelenium Selenium,字符串搜索文本) { int count=(int)Selenium.GetXpathCount(“/*[@id='resultable']/table”); 字符串文本; 布尔发现; 对于(int i=1;i您的大括号不匹配,因此返回值超出了函数定义。真的吗?请计算打开和关闭的大括号。此部分包含的大括号太多。},终止该方法: public bool IsT

正在给予:

return found;
代码:

public bool IsTextPresent(ISelenium Selenium,字符串搜索文本)
{
int count=(int)Selenium.GetXpathCount(“/*[@id='resultable']/table”);
字符串文本;
布尔发现;

对于(int i=1;i您的大括号不匹配,因此返回值超出了函数定义。

真的吗?请计算打开和关闭的大括号。

此部分包含的大括号太多。
},终止该方法:

public bool IsTextPresent(ISelenium Selenium, string searchText)
    {

        int count = (int)Selenium.GetXpathCount("//*[@id='resultTable']/table");
        string text;

        bool found;

        for (int i = 1; i <= count; i++) 
        {
            StringBuilder container = new StringBuilder();

            for (int j = 4; j <= 8; j += 2)
            {

                if (Selenium.IsElementPresent("xpath=/html/body/form/div[2]/table[" + (i) + "]/tr[" + (j) + "]/td[4]"))
                {
                    text = Selenium.GetText("xpath=/html/body/form/div[2]/table[" + (i) + "]/tr[" + (j) + "]/td[4]");


                    container.Append(text + Environment.NewLine);
                }

                string fullText = container.ToString();
                    if (!fullText.Contains(searchText))
                    {
                        found = false;
                    }
                    else
                    {
                        found =  true;
                    }
                }
            }
        }
        return found;            
    }

您有太多的右大括号…结尾缩进的
如果
混淆了您的右大括号数}s:

     string fullText = container.ToString();
                if (!fullText.Contains(searchText))
                {
                    found = false;
                }
                else
                {
                    found =  true;
                }
            }  // remove this one
string fullText=container.ToString();
如果(!fullText.Contains(searchText))
{
发现=错误;
}
其他的
{
发现=真;
}

}//您已将
return found;
放在方法的右大括号之后。请正确对齐代码以查看。在Visual Studio中使用Ctrl-K和Ctrl-D格式化代码。

我知道要处理的问题是大括号,但我会质疑此方法的命名。只有在每个
xpath中找到搜索字符串时,您才会返回true=/html/body/form/div[2]/table[i]
节,或者更具体地说,如果在最后一节中找到它。
     string fullText = container.ToString();
                if (!fullText.Contains(searchText))
                {
                    found = false;
                }
                else
                {
                    found =  true;
                }
            }  // remove this one
        string fullText = container.ToString();
            if (!fullText.Contains(searchText))
            {
                found = false;
            }
            else
            {
                found =  true;
            }
        } // <<<< The indention of the if probably threw you off here...