C# Tips and Tricks, Page 3
Productivity Gains with the Visual Studio C# IDE
The Visual Studio IDE offers a vast number of productivity gains when you have the IDE configured with a C# developer profile.
- Coding shortcuts
- Clipboard ring
- Code snippets
- Visual Studio 2008 Service Pack 1
Visual Studio is chalk full of hundreds of coding shortcuts. I'll call out a few of the ones that I've found to be most helpful.
- Incremental search: Ctrl + I to begin incremental search. You'll notice the mouse pointer will change to binoculars with a downward arrow. Start typing to find a match within the current code file. Ctrl + I again will find the next occurrence in the code file. Ctrl + Shift + I will reverse direction and search upward in the code file.
- Repeat search: F3 to search again for the last item in the Find dialog box. Ctrl + F3 will behave similarly except will include the Match case option.
- Commenting and uncommenting code: Ctrl + K followed by Ctrl + C will comment out the current line or selected block of code. Ctrl + K followed by Ctrl + U will uncomment the current line or selected block of code.
- Indenting: Ctrl + K followed by Ctrl + F will cause Visual Studio to automatically format your code according to the editor formatting rules.
Karen Liu's blog (Microsoft's C# IDE Program Manager) has many, many more useful shortcuts available.
Have you experienced a scenario when you have you cut or copied a line of code only to discover another line of code that you also cut or copy? The original code copied is then lost from the copy buffer and you must undo changes to get back to the first change. The clipboard ring can be your new best friend if this is a common occurrence for you. You cut or copy multiple lines of code independently. Ctrl + Shift + V will allow you to cycle through the code in the clipboard ring. If you are going to use the clipboard ring it is a good idea to consider Tools > Options > Text Editor > All Languages > General and set the "Apply Cut or Copy commands to blank lines when there is no selection" option.
Code snippets are ready-made task-oriented blocks of code. Visual Studio includes a number of default snippets that are activated by typing a specific sequence of keys followed by [tab][tab] to cause the Visual Studio IDE to engage. In addition to typing the snippet in code, you can right-click at the desired location and choose Insert Snippet or Surround With. Here is a very small sampling of what is available.
- Tryf = try and finally block
- Prop = property with get and set accessor
- Switch = switch statement with default
Visual Studio 2008 Service Pack 1
Visual Studio 2008 Service Pack 1 is full of all kinds of goodies that make it worth downloading and installing. The download will take a while, but definitely worth it. Here is a very limited taste of what is included.
- Solution-wide TODO tasks.
- Compiler error "squiggles" on the fly when editing.
- Step into specific that allows you to step in to a particular method call when you have code that has several nested calls as a part of a single statement.
- Many, many, more
You have now seen various tips and tricks related to items within C# 3.0 and the Visual Studio 2008 C# IDE. Hopefully this has provided you some useful insight in to ways you can enhance your C# development experience.
The topic of the next article is likely to be on the Entity Framework. You'll explore what it is and how it compares to LINQ. If you have something else in particular that you would like to see explained here, you could reach me at email@example.com.
About the Author
Mark Strawmyer is an executive with Crowe Horwath LLP in the Indianapolis office. He can be reached at firstname.lastname@example.org.