CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2013
    Posts
    2

    [RESOLVED] New C# programmmer needs help with curly brackets.

    Hello! I recently got a C# book for extra credit for school. I'm having a lot of problems with indenting, when to indent, and how to use curly brackets. For instance, right now I'm working on a project where I am making loops and testing them with Console.Beep(); and I keep getting error messages that my curly brackets are in the wrong place.

    When I go back and try to fix them, Visual Studio 2010 keeps shifting the curly brackets to the left more than I need them (weird I know). For example, if I need my bracket

    here------->{
    It will move it
    here-->{

    Any help would appreciated.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: New C# programmmer needs help with curly brackets.

    You'll have to show your code the indent of the { is not the issue

    If you have pretty code turned on as most do then the IDE tries to format the code for readablility but of course if you have a mistake in there it is not always able to do so.

    As for the code there is no difference between
    Code:
    {
    and
    Code:
           {
    beyond the way it looks when you read it
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Aug 2013
    Posts
    2

    Re: New C# programmmer needs help with curly brackets.

    Thanks for the reply. I guess since I'm familiar with lua and python where brackets and such has to be precise, I freaked out a little. Well, I guess I'll close the thread.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: [RESOLVED] New C# programmmer needs help with curly brackets.

    Id you are still having problems post the code that is giving you a problem and someone should be able to point you in the right direction.
    Always use [code][/code] tags when posting code.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: [RESOLVED] New C# programmmer needs help with curly brackets.

    Btw, in some languages the placement of the opening curly brace is on the same line of the preceding statement.

    Code:
    if( x > 0 ) {
      // other code
    }
    However, in C#, the opening brace generally starts in line with the preceding statement but on the next line.

    Code:
    if( x > 0 )
    {
      // other code
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured