Visual Studio 2008 makes life very easy for a developer. We can have complete code blocks created automatically. This is at a very advanced level for VB.NET and is still evolving for C#.
Right Click and select “Insert Snippet” from the context menu [Or] use Ctrl + K + X and you will see a menu which lists all available options which are neatly grouped.
Just for a sample, I used the insert Snippet to create a code block to “Call the ExecuteReader Method of a SQLCommand” – the following lines were produced automatically:
Dim reader As SqlDataReader
Dim previousConnectionState As ConnectionState = conn.State
If conn.State = ConnectionState.Closed Then
reader = cmd.ExecuteReader()
' Process SprocResults datareader here.
If previousConnectionState = ConnectionState.Closed Then
Some available snippets are listed below:
For C# Code Behind Files
if, Region, Checked, Class, Else, Enum, for, foreach, if, indexer, try, while, Etc.
DependencyProperty Event handler & property.
For VB.NET Code Behind Files
This is a programmer’s delight. The list is very exhaustive. Some samples below:
Code patterns like if, if else, try Catch, property.
Data - ADO.NET - Create a parameterized SELECT Command, Execturereader, Etc.
Data - LINQ - From..Select, From..Order By...Select, Etc.
Collections and Arrays, FileSystems, Math
Connectivity, Crystal Reports, Security, Workflow
Windows Forms – Drawing, Etc
The list is almost endless. See it to believe it…
The use of this feature may lead to code that is NOT in synch with the coding standard on naming conventions of your project/team. So take care of this point.