Question Why doesn't C# automatically add a close } when { is typed?

Neal

Forum Admin
Staff member
Joined
Apr 15, 2011
Messages
246
Location
VA
Programming Experience
10+
So I'm creating a few properties such as:

public string MyName
{

Why when I type that { isn't a } placed for me automatically? It's crazy that I have to enter enter } and then up arrow to code.
 
Yeah, I'm not interested in an add-on for this. I use DevExpress and I'm sure there's something in CodeRush or Refactor I could find. Just odd it doesn't do this by default, common sense isn't it? Oh well!
 
From what I read CodeRush has this, but that's to end of what I can tell about that.
 
Typing a closing brace formats the code within the enclosed block. I think that the intention is that you don't type the closing brace first and then the code, but rather the code first and then the closing brace, at which point the code is formatted. With ReSharper I find that there are various times where I need to overtype the closing brace that it adds anyway in order to auto-format the code.
 
Typing a closing brace formats the code within the enclosed block. I think that the intention is that you don't type the closing brace first and then the code, but rather the code first and then the closing brace, at which point the code is formatted.
I thought that was the job for the semi-colon.... the end brace does a better job at it I must admit. Takes a while getting used to when coming from VB.Net that auto close when a code block is opened.
 
I thought that was the job for the semi-colon.... the end brace does a better job at it I must admit. Takes a while getting used to when coming from VB.Net that auto close when a code block is opened.
The semi-colon formats a line but the closing brace formats the entire block. Sometimes line by line formatting is enough but there are many occasions where it's not.
 
Type:

prop(TAB)(TAB)

For the way youre supposed to write properties in c# :)

Also many other words can replace prop above: tryc tryf ctor for psvm ...

Press ctrl space on an empty line to see (think it's a White icon in intellisense)

I guess the reason c# doesn't do it is cos it's not vb: c# pro-grammers remember to close their braces :)
 
Back
Top Bottom