Both VB.Net and C# have automation built in when it comes to creating blocks. However, C#’s implentation is quite a bit less robust.
Creating a new block
VB.Net
To Create a new class, method, and property in VB.Net, you could type:
public class TheClass<enter>
public property TheProperty as string<enter>
<down><down><down><down><down><end><enter>
public sub TheMethod<enter>
Result (including important cursor positions):
Public Class TheClass
Public Property As String
Get
|
End Get
Set(ByVal value As String)
|
End Set
Public Sub TheMethod()
|
End Sub
End Class
C#
To Create a new class and method in C#, you could type:
public class TheClass {}<home><enter><up><tab>
public String MyProperty {}<home><enter><up><tab>
get {}<home><enter><up><tab>
<down><enter>
set {}<home><enter><up><tab>
<down><down><down>
public void TheMethod() {}<enter><home><enter><up><tab>
or (using shortcuts)
public class TheClass {}<ctrl-enter>
public String MyProperty {}<ctrl-enter>
get {}<ctrl-enter>
<down><enter>
set {}<ctrl-enter>
<down><down><enter>
public void TheMethod() {}<enter><ctrl-enter>
Result (including important cursor positions):
public class TheClass {
public String MyProperty {
get {
|
}
set {
|
}
}
public void TheMethod() {
|
}
}
C# Inconsistencies
If there is a syntax error (e.g. unclosed block) near the new block, it will not be auto-completed or auto-formatted.
Comparison
Luckily for C#, <ctrl-enter> exists. Otherwise, you would have to type <home><enter><up><tab>. However, it took me a while to find this shortcut and get used to using it.
Without the shortcut, there are 6 extra keys to hit. With the shortcut, there are only 2 extra keys plus a combo key instead of just enter (so 3 extra keys).
On top of the extra keys in C#, you must make sure all the syntax is correct or else auto-complete will not happen.
Auto-formatting of existing blocks
This is where C# really shows its inferiority. Once stuff gets moved around, the only way to get back to standard formatting is to make sure there are no syntax errors and then hit <ctrl-K><ctrl-D>. Well, that or manually move it… but are we using an IDE here or Notepad?
There are lots of reasons this C# will not auto-format your block for you even after hitting <ctrl-K><ctrl-D>. For example, if a previous block is unclosed, or if there is a syntax error somewhere nearby, such as missing a ‘;’ inside the block.
Feelings on the Matter
I find myself constantly hitting <ctrl-k><ctrl-d> (shortcut for format document) while programming in C#, since the formatting of the document becomes non-standard after a bit of editing.
Basically, VB.Net’s philosophy is: auto-format all the time, unless you are talking about a line continuation (using an underscore character).
C#’s philosophy seems to be: auto-format only when finishing a block and there are no syntax errors to speak of nearby.