Visual Studio 2010–New and little-know features–Part 3–IntelliSense Improvements

Mind-reader

Table of Contents for this series.

Sometimes it’s the most subtle improvements that make the biggest difference to your productivity.  Some of these subtle improvements falls into the “Search” and “IntelliSense” categories.  Visual Studio 2010 improved the way that it helps us save keystrokes and how we discover the capabilities of the classes in our programs.

IntelliSense features

Add using  (C# only)

The Add using feature is pretty cool.  IntelliSense reviews your Type usage.  If it finds that you have declared a variable of a Type that is not a member of one of the declared Namespaces (those listed with a Using statement at the top of the file) it will flag this “unbound type” with the dreaded “red squiggly” with a message of “C#: Unknown type”.  It will then look around all of the referenced assemblies in your project for a matching type. If it finds one or more namespaces that contain a Type with the declared name, it will add a Smart Tag to the unbound type.  In the example below, I’m declaring a variable t of type Timer.  The Timer type is not bound to a known namespace.  The Smart Tag is the blue line below the word Timer.

SNAGHTML102c6c

When you place the mouse over the tag it will expand to give you the option of adding a Using statement to the top of the file, fully-qualify the Type declaration or let it generate a new class or type for you.

SNAGHTML1478e6

This way you don’t have to go hunting around for the namespace reference and then pop to the top of the file to add the Using statement. You can just keep working where you are and let IntelliSense handle it for you without a disruption to your workflow.

MSDN Library – Add using


“Contains” searching

In Visual Studio versions prior to 2010, the IntelliSense system would return matching classes or methods based on a “Starts with” search pattern.  So if you have a variable List numbers and want to get the available methods and properties, you just type the variable name then a period and IntelliSense will display the available properties and methods.  IF you keep typing, the list will be filtered down to those entries that start with the text that you type.  In the example below, I typed numbers.as and the list filtered down to just the members that began with “As”.

SNAGHTML2ae5ec

Starting in Visual Studio 2010, we can now do a contains search, so given the code above, I can write numbers.inde and I’ll see entries that start with inde but also ones that contain inde

SNAGHTML2fc3cc

 

Camel case searching

You can also search for members by typing just the capital letters of the member.  So using the prior example, if I know want to use one of the IndexOf methods, I can type numbers.IO and IntelliSense will show me IndexOf and LastIndexOf members.  This only work because I used CAPITALS.  If I had typed numbers.io it would have brought up members that contained “io” together.

SNAGHTML35bb24

 

Table of Contents for this series.