Search code examples
c#curly-bracesmismatch

How to fix: Mismatching (Curly) Brackets


I just started at programming (C#) at uni and have my first exam next friday. But just now, my project started to mismatch all my curly braces and I can't seem to fix it.

To define my problem a bit more: When I place the combination of a opening and closing brackets (i.e. "{}") after a class for example, and continue to create a method (adding a new pair of curly brackets again) the opening bracket of the class matches with the closing bracket of the method. Which results in a "wrong" code. (see code below; the 1 shows which brackets match with each other)

I'm kinda desperate and was hoping you guys could help me out in fixing this.

Thanks in advance!

    class KopieForm : Form
     1{
          public KopieForm
          {
              this.Text = "KopieDemo";
              this.BackColor = Color.White;
              this.Size = new Size(680, 340);
              this.Paint += this.KopieDemo;
         1}
      }     

Solution

  • Your constructor syntax is not correct. You need parenthesis otherwise it won't compile. Try this:

        class KopieForm : Form
     {
          public KopieForm() //notice the ()
          {
              this.Text = "KopieDemo";
              this.BackColor = Color.White;
              this.Size = new Size(680, 340);
              this.Paint += this.KopieDemo;
         }
      }