Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid token 'return' in class, struct, or interface member declaration

Tags:

c#

return found;

is giving:

Invalid token 'return' in class, struct, or interface member declaration

Code:

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;            
    }
like image 432
Maya Avatar asked Dec 22 '25 23:12

Maya


2 Answers

You have too many closing curly braces... Your indented if at end is confusing your number of closing }s:

        string fullText = container.ToString();
            if (!fullText.Contains(searchText))
            {
                found = false;
            }
            else
            {
                found =  true;
            }
        } // <<<< The indention of the if probably threw you off here...
like image 174
James Michael Hare Avatar answered Dec 24 '25 12:12

James Michael Hare


Your braces mismatch, so the return is outside the function definition.

like image 44
Ed Bayiates Avatar answered Dec 24 '25 13:12

Ed Bayiates



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!