Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';找不到预期的}_C# - Fatal编程技术网

C# Can';找不到预期的}

C# Can';找不到预期的},c#,C#,我似乎找不到将}放在这个代码段的什么地方。 这个问题很简单,但我没法解决 foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt")) { if (line.Contains("@")) { searchEmail.SendKeys(

我似乎找不到将}放在这个代码段的什么地方。 这个问题很简单,但我没法解决

                foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))         
            {
                if (line.Contains("@"))
                    {
                    searchEmail.SendKeys(line);
                    submitButton.Click();
                    var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
                    var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
                    if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
                    // If invite_someone_failure exists open this url
                    driver.Url = "https://www.tumblr.com/lookup";
                    Thread.Sleep(3000);
                    driver.Url = "https://www.tumblr.com/following";
                    else
                    using (StreamWriter writer = File.AppendText("C:\\tumblrextract\\out7.txt"))
                        writer.WriteLine(result + ":" + line);
                    }
                }

在else之前你需要}在else之后你需要{。你还需要为第二个if打开一个右括号

foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))         
            {
                if (line.Contains("@"))
                    {
                    searchEmail.SendKeys(line);
                    submitButton.Click();
                    var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
                    var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
                    if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
                    {
                       // If invite_someone_failure exists open this url
                       driver.Url = "https://www.tumblr.com/lookup";
                       Thread.Sleep(3000);
                       driver.Url = "https://www.tumblr.com/following";
                     }//end of second if
                    else{
                         using (StreamWriter writer =File.AppendText("C:\\tumblrextract\\out7.txt"))
                         writer.WriteLine(result + ":" + line);
                        }//end of else
                    }//end of first if
                }//end of foreach

在else之前你需要}在else之后你需要{。你还需要为第二个if打开一个右括号

foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))         
            {
                if (line.Contains("@"))
                    {
                    searchEmail.SendKeys(line);
                    submitButton.Click();
                    var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
                    var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
                    if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
                    {
                       // If invite_someone_failure exists open this url
                       driver.Url = "https://www.tumblr.com/lookup";
                       Thread.Sleep(3000);
                       driver.Url = "https://www.tumblr.com/following";
                     }//end of second if
                    else{
                         using (StreamWriter writer =File.AppendText("C:\\tumblrextract\\out7.txt"))
                         writer.WriteLine(result + ":" + line);
                        }//end of else
                    }//end of first if
                }//end of foreach

正确的格式有助于您自己查找错误。不过,这是因为在
if(driver.find…
之后有3条语句,而
else
则需要在前面加一个大括号。将条件语句用大括号括起来,这样就可以了

foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))
{
    if (line.Contains("@"))
    {
        searchEmail.SendKeys(line);
        submitButton.Click();
        var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
        var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
        if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
        {
            driver.Url = "https://www.tumblr.com/lookup";
            Thread.Sleep(3000);
            driver.Url = "https://www.tumblr.com/following";
        }
        // If invite_someone_failure exists open this url
        else
        {
            using (StreamWriter writer = File.AppendText("C:\\tumblrextract\\out7.txt")) 
            {
                writer.WriteLine(result + ":" + line);
            }
        }
    }
}

正确的格式有助于您自己查找错误。不过,这是因为在
if(driver.find…
之后有3条语句,而
else
则需要在前面加一个大括号。将条件语句用大括号括起来,这样就可以了

foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))
{
    if (line.Contains("@"))
    {
        searchEmail.SendKeys(line);
        submitButton.Click();
        var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
        var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
        if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
        {
            driver.Url = "https://www.tumblr.com/lookup";
            Thread.Sleep(3000);
            driver.Url = "https://www.tumblr.com/following";
        }
        // If invite_someone_failure exists open this url
        else
        {
            using (StreamWriter writer = File.AppendText("C:\\tumblrextract\\out7.txt")) 
            {
                writer.WriteLine(result + ":" + line);
            }
        }
    }
}

使用pro power tool进行正确的缩进,它将自动为您进行缩进。您将很容易得到错误。谢谢使用pro power tool进行正确的缩进,它将自动为您进行缩进。您将很容易得到错误。谢谢