none
Mismatching (Curly) Brackets RRS feed

  • Question

  • Hi!

    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 brackets 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 bracket (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. 

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

    Thanks in advance!

    Monday, September 25, 2017 3:30 PM

All replies

  • Difficult to know exactly what is wrong without seeing your code (and the exact error message you are getting). But generally your file should look something like this:

    using System;
    // any other assemblies used would go here
    
    
    namespace MyNamespace
    {
        public class MyClass
        {
            public void MethodOne()
            {
     
            }
    
            public int MethodTwo(int anArgument)
            {
                return anArgument * 2;
            }
        }
    }

    Obviously this is a meaningless class - it's just a demonstration of the basic syntax. Its a simple class called MyClass that contains two methods. MethodOne does not take any arguments or return anything. MethodsTwo takes a single integer argument and returns double the number passed in.

    If you still can't see what is wrong with your code then paste it up here using the 'Insert code block' button
    • Edited by RJP1973 Monday, September 25, 2017 3:37 PM
    • Proposed as answer by Fei HuModerator Friday, October 6, 2017 6:29 AM
    Monday, September 25, 2017 3:36 PM
  • Thanks for the quick response!
    I still can't see what I did wrong. Below you can find (a part of) my code; the 1's show which braces match with each other and are not actually in the code.

    using System.Windows.Forms;
    using System.Drawing;
    using System.IO;
    
    class KopieForm : Form
    1{
        public KopieForm
            {
            this.Text = "KopieDemo";
            this.BackColor = Color.White;
            this.Size = new Size(680, 340);
            this.Paint += this.KopieDemo;
            1}
    }
    Edit: Found it; forgot the () after the method KopieForm. I'm sorry for my newby-like question ;)

    • Edited by Phaken Monday, September 25, 2017 3:59 PM
    • Proposed as answer by Barry WangModerator Wednesday, September 27, 2017 10:00 AM
    Monday, September 25, 2017 3:51 PM
  • Hello Phaken,

     public KopieForm()
            {
            }

    If the issue has been solved by yourself ,you could mark the your own reply as answer . This can be beneficial to other community members reading this thread if they are struck in the same issues.

    Sincerely,

    feih


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 26, 2017 3:21 AM
    Moderator