Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Damn c# { }'s

Damn c# { }'s

Scheduled Pinned Locked Moved The Lounge
csharpquestioncareer
68 Posts 47 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R RossMW

    Yes, very dimly. Makes it hide to find when you have to scroll to see it. Just have to remember the Left brace, right brace, back arrow, code... dance move...

    M Offline
    M Offline
    Member 11495478
    wrote on last edited by
    #38

    You can also use this to find the matching "{}" On the keypad use the Ctrl key on the right side of the keyboard. Press right Ctrl ] key combination. This will take you to the matching "{}".

    1 Reply Last reply
    0
    • R RossMW

      Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

      B Offline
      B Offline
      BC3Tech
      wrote on last edited by
      #39

      Use the Tools.[^]

      1 Reply Last reply
      0
      • D Duncan Edwards Jones

        Left brace, right brace, back arrow, code...

        A Offline
        A Offline
        adriancs
        wrote on last edited by
        #40

        { } Left + Top Enter ...Code...

        1 Reply Last reply
        0
        • D Duncan Edwards Jones

          Left brace, right brace, back arrow, code...

          A Offline
          A Offline
          adriancs
          wrote on last edited by
          #41

          { } Left Enter Top

          1 Reply Last reply
          0
          • M Marc Clifton

            RossMW wrote:

            and then trying to figure which } belong with which {

            Dang, doesn't the IDE (dimly, I'll grant) light up the matching braces? [on my high horse] If you have that much nesting, maybe you should break the function apart into smaller calls? [/on my high horse] Marc

            Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

            M Offline
            M Offline
            Member 10707677
            wrote on last edited by
            #42

            Before they started colour matching the {}, I got into the habit fo placing a comment following the closing brace with an inverted reference to the starting brace procedure name.

            The difficult may take time, the impossible a little longer.

            1 Reply Last reply
            0
            • R RossMW

              Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

              T Offline
              T Offline
              The Great Kazoo
              wrote on last edited by
              #43

              What I have been known to do: void SomeLongFunction { // many lines of code } // end void SomeLongFunction

              1 Reply Last reply
              0
              • R RossMW

                Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                A Offline
                A Offline
                Adam P L
                wrote on last edited by
                #44

                No just use Resharper it does it for you.

                1 Reply Last reply
                0
                • R RossMW

                  Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                  M Offline
                  M Offline
                  Member11140258
                  wrote on last edited by
                  #45

                  In VS you can just use ctrl+'}' on one of the braces to toggle to what VS thinks is the match. This can be done for any open and close types, html tag or ( ) etc. VS2013 will add both for you by default as you type.

                  1 Reply Last reply
                  0
                  • D Duncan Edwards Jones

                    That it pretty much is - definitely muscle memory at this stage.

                    D Offline
                    D Offline
                    DerekT P
                    wrote on last edited by
                    #46

                    Is it just me... VS2013 automatically creates the closing bracket whenever I type an opening...?

                    J 1 Reply Last reply
                    0
                    • R RossMW

                      Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                      A Offline
                      A Offline
                      Alexander DiMauro
                      wrote on last edited by
                      #47

                      RossMW wrote:

                      Do you have any tips on keeping these damn { } under control?

                      Yes, it's called ReSharper[^] I've been using it since 2009 and I have no idea how to use Visual Studio anymore without it.

                      I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone - Bjarne Stroustrup The world is going to laugh at you anyway, might as well crack the 1st joke! My code has no bugs, it runs exactly as it was written.

                      1 Reply Last reply
                      0
                      • S Sascha Lefevre

                        You can change the color of the highlighting :) clicky[^]

                        If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                        D Offline
                        D Offline
                        DumpsterJuice
                        wrote on last edited by
                        #48

                        What was the setting name you changed to do that? Where there's smoke, there's a Blue Screen of death.

                        S 1 Reply Last reply
                        0
                        • D DumpsterJuice

                          What was the setting name you changed to do that? Where there's smoke, there's a Blue Screen of death.

                          S Offline
                          S Offline
                          Sascha Lefevre
                          wrote on last edited by
                          #49

                          Tools > Options > Environment > Fonts and Colors > Brace Matching (Rectangle) Just overlooked it myself first on first try ;)

                          If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                          D 1 Reply Last reply
                          0
                          • R RossMW

                            Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                            P Offline
                            P Offline
                            patbob
                            wrote on last edited by
                            #50

                            Find matching brace (most code editors have one) -- Visual Studio: ctrl-], Vi: % Use a smart editor that automatically adds, shows or otherwise assists in making sure you have balanced brackets. Consistent indentation. It also helps not to have large blocks of code, but sometimes that just can't be avoided. It is a pain sometimes, but I've just learned to live with it since the previous alternatives were much, much worse.

                            We can program with only 1's, but if all you've got are zeros, you've got nothing.

                            1 Reply Last reply
                            0
                            • S Sascha Lefevre

                              Tools > Options > Environment > Fonts and Colors > Brace Matching (Rectangle) Just overlooked it myself first on first try ;)

                              If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                              D Offline
                              D Offline
                              DumpsterJuice
                              wrote on last edited by
                              #51

                              Thanks for such a quick reply! > from Charlotte, NC, USA Where there's smoke, there's a Blue Screen of death.

                              1 Reply Last reply
                              0
                              • R RossMW

                                Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #52

                                How long is on average one of your methods? A method shouldn't be longer than a screen, which makes around 50 lines of code. This will solve your braces problem immediately.

                                1 Reply Last reply
                                0
                                • R RossMW

                                  Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                                  F Offline
                                  F Offline
                                  fglenn
                                  wrote on last edited by
                                  #53

                                  I don't know about anyone else, but when I enter a '{', I also enter the corresponding '}' before I insert any code in between the braces. I never have a problem with unbalanced/misplaced braces.

                                  Fletcher Glenn

                                  1 Reply Last reply
                                  0
                                  • D DerekT P

                                    Is it just me... VS2013 automatically creates the closing bracket whenever I type an opening...?

                                    J Offline
                                    J Offline
                                    JRickey
                                    wrote on last edited by
                                    #54

                                    It does for me, also. I still have the default setup. Note that it also does that in text documents, when I don't want it to. And in code, typing the closing element can add an extra one (I think that happens if I use cursor keys to edit before closing).

                                    1 Reply Last reply
                                    0
                                    • M Marc Clifton

                                      RossMW wrote:

                                      and then trying to figure which } belong with which {

                                      Dang, doesn't the IDE (dimly, I'll grant) light up the matching braces? [on my high horse] If you have that much nesting, maybe you should break the function apart into smaller calls? [/on my high horse] Marc

                                      Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                                      T Offline
                                      T Offline
                                      TNCaver
                                      wrote on last edited by
                                      #55

                                      Marc Clifton wrote:

                                      Dang, doesn't the IDE (dimly, I'll grant) light up the matching braces?

                                      Only when you put the cursor just after the } or just before the {. Not if the cursor is inside the block in question.

                                      If you think 'goto' is evil, try writing an Assembly program without JMP.

                                      1 Reply Last reply
                                      0
                                      • R RossMW

                                        Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                                        J Offline
                                        J Offline
                                        James Curran
                                        wrote on last edited by
                                        #56

                                        Obviously, you are using the god-forsaken "K&R" bracing style

                                        if (condition) {
                                        /// stuff
                                        }

                                        When you choose a coding style based on readability rather than historic fanboy popularity, these problems go away:

                                        if (condition)
                                        {
                                        // Stuff
                                        }

                                        Truth, James

                                        1 Reply Last reply
                                        0
                                        • R RossMW

                                          Now, I am not interested in a VB versus C# debate but. In my job I only spend about 20% of my time coding. Being from a C# background anything new I would normally do in C# (and yes very occasionally VB), but I also have to maintain old VB code (and heaven forbid, very occasionally VB6). Normally I spent a month or two in each language (depending on the task at hand) and are happy in any camp. Changing back and forth between languages is relatively straight forward, but lately I noticed it takes me longer to get back into swing of C#. And the reason.. Well, I think its because I've got myself into bad c# typing habits from using vb. I seem to be wasting so time chasing missing / misplaced { }, forgetting semicolons case sensitivity and ()'s. Now semicolons, case and () problems are just a "Oh Bugger" moment, but as for missing / misplaced { } 's. They can be time waster. For all you pro c# developers, Do you have any tips on keeping these damn { } under control?

                                          U Offline
                                          U Offline
                                          User 4598947
                                          wrote on last edited by
                                          #57

                                          When there's too much nesting, and therefore too many braces, consider 1) refactor out inner nestings into new methods 2) label }'s:

                                          namespace foo
                                          {
                                          public class bar
                                          {
                                          public void fu()
                                          {
                                          for(var int i = 0; i < 10; i++)
                                          {
                                          if(Math.PI != 0.0)
                                          {

                                                      } // if PI not 0
                                          
                                                  } // for i
                                          
                                              } // fu
                                          
                                          } // bar
                                          

                                          } // foo

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups