.gif) view larger >
| IntelliSense This is one of the most popular features of Visual Studio. It can save you countless hours over the course of a project. IntelliSense provides statement completion as you type for quickly accessing properties, methods, and events. Upon typing the name of an object, typing dot "." causes a popup list to appear that displays the available elements. The diagram shows the available methods and properties for the List class. |
.gif)
| IntelliSense is also invaluable for writing code such as exception handling. When adding a Try/Catch block, IntelliSense filters the available options to show only a list of exception types. |
.gif)
| This filtering also applies to attributes. Attributes let you specify descriptive metadata for a method, class, or assembly. For example, you can update your application version number by updating the AssemblyVersion attribute. Our diagram shows how IntelliSense will automatically filter to show only attribute types. |
| |
.gif) | IntelliSense Code Snippets To make writing code easier, Visual C# Express includes a feature called IntelliSense Code Snippets which are extensible fill-in-the-blank snippets of code. Visual C# Express includes over 30 pre-built language code snippets for many tasks, such as adding a property, switch statement, and try/catch exception handling. To insert a snippet, you can either type the snippet shortcut, like "prop" for property, right-click anywhere in your code, or just click Insert Snippet… to select the snippet you need. The diagram below shows the context menu for choosing your snippet. |
.gif)
| Once you've inserted the snippet, you'll notice fill-in-the-blank regions highlighted in green for you to edit and customize to your needs. For snippets with multiple fill-in-the-blank regions, you can jump from region to region use the tab key for quick editing. |
.gif)
| Some code snippets are "smart" based on the custom value you enter. For example, using an enumeration with the switch code snippet will automatically add case statements for each possible value in your enumeration. IntelliSense Code Snippets can also be customized, so you can create your own and share them with fellow coders! You can learn more about customizing your own IntelliSense Code Snippets. |
| |
.gif) | Rename refactoring Visual C# Express includes support for the Rename and Extract Method refactorings. Refactoring is the process of restructuring your code. Visual C# Express automates the code restructuring process. |
.gif) view larger >
| Once you've written a lot of code in a project, it can be tedious to rename a poorly named variable—as you may have 10, 20, or 100 different lines of code to manually change. Visual C# Express includes support for the Rename refactoring so that you only need to make one change and the tool will update all of the correct references for you. You can rename anything, including namespaces, classes, parameters, variables, and more. To use the Rename refactoring, simply right-click a variable name (such as textBox1) and select Refactor… Rename…. You are then prompted to enter a new name for textBox1 with the option to search comments and strings. |
.gif) view larger >
| You will then see a listing of all of the code and comments that will be affected by this change. Clicking a specific reference will show a preview of what the new code will look like, with newly renamed items highlighted. |
| |
.gif) | Extract Method Refactoring The Extract Method Refactoring automates the process of extracting out a selection of code as its own method. The Extract Method Refactoring makes it easier to better organize your code. It also makes your code more modular and reusable, with less duplication. For example, you may have a section of code that accomplishes more than one task, such as displaying values on a form and updating results. You probably want to be able to update results from other places in your application as well. Rather then duplicating code, you can extract the updating results code using the Extract Method Refactoring. |
.gif) view larger >
| To use the Extract Method Refactoring, simply right-click the selection of code you want to extract and select Refactor… Extract Method… The Extract Method dialog box will ask for a name for the new method and will show you a preview of what the extracted method will look like. The Extract Method refactoring intelligently decides the return value and parameters for the extracted method. |
.gif)
| After running the Extract Method refactoring, notice that your selection of code is replaced with a call to the newly extracted method, which can now be reused in your application. |
| |
.gif) | Surround With The Surround With feature makes it easy to "surround" a selection of code with a number of built-in IntelliSense Code Snippets. You can, for example, surround a selection of code with a "for" loop, "if" statement, "try/catch" exception handling, and more. To use Surround With, simply right-click the selection of code you want to surround and select Surround With…. |
.gif)
| You'll then be prompted to select the code snippet with which you want to "surround" the selection. In our example here, we'll surround the selected code with "try/catch" exception handling. This will provide a graceful way to handle any exceptions which may occur while we're executing the code. (If we "try" to open a file and there is a problem finding the file, we'll want to "catch" that exception gracefully and handle the error condition.) |
.gif)
| After you select the appropriate code snippet, the selected code is automatically placed in the try block with the customizable exception type highlighted in green. |
| |
.gif) view larger >
| Generate Method Stub The Generate Method Stub feature automatically creates a method stub for you if you call a method that you haven't written yet. To see it in action, you simply need to write out the method name, set the return value, and pass in any parameters. Visual C# Express will intelligently know that this is a new method and display a smart tag to automatically generate the method stub for you. |
.gif) view larger >
| The new method stub is then created using the name chosen earlier, and the exception parameter is automatically inferred in the method signature. You can then replace the "not implemented" exception with your own custom code. |
| |
.gif)
| Auto-Using One challenge for new developers is that IntelliSense can stop "working" in Visual C# Express. The most common reason for this is that your code is missing a using statement to fully qualify the data type. The tool will intelligently detect whether your code is missing a using statement, and display a smart tag to either add the appropriate using statement or provide the fully qualified name of the type. |
| |
.gif) view larger >
| XML Comments XML comments are a way to add documentation to your code in a simple and uniform way. By adding three slashes in a row (///) at the beginning of a method, Visual C# Express will dynamically generate the XML template, including the parameters and return values. This XML data can be read by other popular documentation generation tools, such as NDoc, to produce professional-looking documentation for your application or component. |
| |
.gif) | Task List Similar to an Outlook task list, the Task List lets you keep track of tasks that you have to complete in your coding project. You can automatically add an entry into your task list by simply adding a comment in your code using the following format "//TODO: My comment here". You can then double-click any task in the Task List to jump directly to the corresponding line of code. |
| |
.gif) | Find All References When developing large solutions, it may be helpful to determine where a particular class or member is referenced throughout the solution. To do this, right-click the class, then click Find All References. This displays all references to that class throughout the current solution. This technique is more accurate than using the standard find functions, as it uses the compiler to find the exact matches for the corresponding class. |
| |
.gif) view larger >
| Navigate code Finding your way around source code files can involve lots of scrolling. Visual C# Express makes this navigation easier with two drop-down lists in the source designer pane. The list on the left allows you to choose from one or more class definitions in the file, while the list on the right lets you jump right to the method or type in question. |
| |
.gif) | Go To Definition Finding sections of code can sometimes be challenging. But Visual C# Express makes this much easier. For example, right-clicking a variable or a class and choosing Go To Definition takes you to the place in the code where the type was defined. |
.gif)
| If no source code is available for the type, as with the string class, Visual C# Express will automatically generate a source code file for you based on the class metadata. |