I was watching one of the MSDN Screencasts today and Mike Taulty put in a switch statement that pre-populated itself with valid values for each of the case statements within the switch. I hadn’t seen this before so I investigated further (in other words, I emailed Mike and asked him what he did). It turns out this is a feature that has been in since Visual Studio 2005 and I’d only just noticed.
Essentially, if you are switching on an enumerator the snippet will expand with all the case statements created for you as you can see by the animation below. To access this, follow these steps
- Type “switch”, the intellisense will show the word “switch” with the torn document icon, indicating it is a snippet.
- Press the tab key twice to expand the snippet, this will also highlight the text “switch_on”.
- Change the “switch_on” text to the name of the variable on which you want to switch.
- Press return twice, this will further expand the switch statement filling in all the cases from the enumerator.
For an example, see the animation below: