“错误CS1513:}预期”在我的“Form1.cs”中救命! :( [英] "error CS1513: } expected" in my "Form1.cs" HELP! :(

查看:110
本文介绍了“错误CS1513:}预期”在我的“Form1.cs”中救命! :(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个非常大的问题,这让我烦恼,似乎只需要一个简单的改变,但我不知道是什么!我正在使用Visual Studio 2010.



这是我的代码:



Hello, I am having a really big problem that is bugging me, and it seems like it only needs a simple change, but I don't know what! I am using Visual Studio 2010.

Here is my code:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if(checkBox1.Checked)
    {
        FlashingName = true;
        timer1.Enabled = true;
        timer1.Start();
    }
    else

        FlashingName = false;
        timer1.Enabled = false;
        timer1.Stop();

    }







问题是最后一个}。




The problem is the very last "}".

推荐答案

您应该在 else 关键字之后添加一个括号 {。您还应该在方法的末尾添加另一个括号:
You should add a bracket { after the else keyword. You should also add another bracket at the end of your method:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if(checkBox1.Checked)
    {
        FlashingName = true;
        timer1.Enabled = true;
        timer1.Start();
    }
    else
    {   // add this bracket
        FlashingName = false;
        timer1.Enabled = false;
        timer1.Stop();
 
    }
} // also add this bracket







顺便说一下, timer1.Enabled = true; timer1.Start(); timer1.Enabled = false; 相同与 timer1.Stop();

相同所以你可以通过写这个来简单地优化你的代码:




By the way, timer1.Enabled = true; does the same as timer1.Start(); and timer1.Enabled = false; does the same as timer1.Stop();
So you can simply optimize your code by writing this:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    FlashingName = checkBox1.Checked;
    timer1.Enabled = checkBox1.Checked;
}



如果 checkBox1.Checked true ,然后 FlashingName timer1.Enabled true 也。如果 checkBox1.Checked false tiemr1.Enabled FlashingName false


If checkBox1.Checked is true, then FlashingName and timer1.Enabled will be true also. Same if checkBox1.Checked is false: tiemr1.Enabled and FlashingName will be false


是。它缺少了!



你的方法必须以}结束,但我从缩进中怀疑,你实际做的是忘记了开头 else 条件的括号:

Yes. It's missing!

Your method must start, and end with a "}", but I suspect from the indentation, that what you've actually done is forgotten the opening bracket of the else condition:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if(checkBox1.Checked)
    {
        FlashingName = true;
        timer1.Enabled = true;
        timer1.Start();
    }
    else
    {
        FlashingName = false;
        timer1.Enabled = false;
        timer1.Stop();
    }
}


基本上,我在我的代码中看得更远,哪里有不同的},你只需要在代码底部添加更多内容,但与其一致。希望这是有道理的:)



Basically, I looked further up in my code and where there were different "}", you just have to add more at the bottom of your code, but in line with them. Hope this makes sense :)

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                FlashingName = true;
                timer1.Enabled = true;
                timer1.Start();
            }
            else
            {
                FlashingName = false;
                timer1.Enabled = false;
                timer1.Stop();

            }
        }
    }
}


这篇关于“错误CS1513:}预期”在我的“Form1.cs”中救命! :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆