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

Neal

Forum Admin
Staff member
Joined
Apr 15, 2011
Messages
109
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.
 

Neal

Forum Admin
Staff member
Joined
Apr 15, 2011
Messages
109
Location
VA
Programming Experience
10+
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!
 

AnnieMacD

New member
Joined
Apr 23, 2011
Messages
1
Location
Scotland, UK
Programming Experience
10+
Resharper also completes braces. You have to purchase it but worth every penny IMO.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,140
Location
Sydney, Australia
Programming Experience
10+
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.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
814
Location
Norway
Programming Experience
10+
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.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,140
Location
Sydney, Australia
Programming Experience
10+
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.
 

cjard

Member
Joined
Jan 25, 2012
Messages
5
Programming Experience
10+
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 :)
 
Top Bottom