Visual Studio Tips

Dot Net Perls

.NET VS

Visual Studio logo (Copyright Microsoft)

Programs are text: they can be edited in any text editor. With an integrated development environment such as Visual Studio, though, you can use features that make programs easier to compose—IntelliSense completes statements, refactoring options rewrite methods, TODO comments remind you of tasks. To reduce the headaches of C# programming, Visual Studio comes in handy—it's nearly essential.

Features

To start, let's look at some of the features of Visual Studio. Most of these features are available in Visual Studio Profession 2008 and 2010, as well as Visual C# Express 2008 and 2010. Visual Studio 2005 also has much of the same functionality.

IntelliSense Debugging Tutorial Activation Record Comment Selection TODO Comments Omit Curly Brackets

Refactoring. Continuing on, Visual Studio provides tools for you to refactor your code automatically. These features can be very useful at times, particularly for the less involved refactoring maneuvers.

Encapsulate Field Find All References Organize UsingsPointer in Toolbox

Other features. We next present features of Visual Studio that do not primarily involve the C# language. They can be useful for formatting XML files and also controlling build options for unmanaged programs.

Tab Options Post-Build, Pre-Build Macros Pointer

Settings.settings

For Windows Forms programs, you can use Visual Studio to store data persistently throughout application executions. This feature involves the Settings.settings file and is described here.

Settings.settingsUsing keyword

Extern alias

The extern alias directive allows you to specify a physical location of a class in addition to its name. This helps when you have two class libraries that introduce a class with the same name.

Extern Alias Using Alias

Debug

The Visual Studio integrated development environment also allows you to use some useful methods in your programs to debug. These include the Debug.Assert and Debug.Write methods—they are described here.

Debug.Assert Debug.Write Debug.WriteLineIf

Snippets

One neat feature in the Visual Studio IDE is snippets: these allow you to type a few letters and then press tab twice to insert a common fragment of code. They can be useful to reduce repetitive statements and reduce overuse injuries with your hands.

Prop snippet (Visual Studio screenshot) ctor class cw do lock mbox prop propfull sim svm switch using

Tip: The most useful snippet I know of is probably the prop snippet, which is linked to above. It's a personal favorite of mine.

Summary

The C# programming language

Visual Studio not only provides a way to write C# and VB.NET programs, but it has many features that make writing these programs significantly easier. It is worthwhile to spend some effort to improve your skills using Visual Studio.

Visual Studio 2008 Review