What are code snippets and how do we use them in Visual Studio?
They are short pieces of code which get generated using a few characters followed by pressing the tab button twice.
For example, to create a class or property, you could type class+tab+tab or propg+tab+tab.
What are class and class associated snippet commands? (hint: 4)
class
ctor (constructor)
prop
propg (get only)
What are the looping snippet commands? (hint: 4)
1. for
2. foreach
3. do
4. while
What are commonly used code snippet commands not associated with a class or loop? (hint: 8)
1. try/tryf
2. switch
3. else
4. enum
5. struct
6. interface
7. indexer
8. cw (Console.Write())
What are the top 8 keyboard shortcuts?
1. ALT+LEFT ARROW (move forward in history)
2. ALT+RIGHT ARROW (move backwards in history)
3. CTRL+C (copy current line/item)
4. CTRL+V (paste current line/item)
5. CTRL+SHIFT+S (save all files in solution)
6. CTRL+TAB (next tab)
7. CTRL+ (move forward to last location)
8. CTRL- (move backwards to last location)
If you forget a particular code snippet or want to see if one exists, what snippet is needed to view ALL code snippets for various languages and technologies?
CTRL+K+X
This will give you intellisense values for C#, Testing, MVC, and others including those for loops, events, delegates, classes, and much more.
What shortcut should you use to comment or un-comment lines of code?
CTRL+K followed by CTRL+C
CTRL+K followed by CTRL+U
What shortcut is used to select the current line? How about those above or below?
SHIFT+HOME
SHIFT+END
SHIFT+ALT+UP ARROW
SHIFT+ALT+DOWN ARROW
Can you create your own snippet? How?
Yes. Each are controlled by Visual Studio and exist in their own XML file. First create the snippet in XML and name it something with the *.snippet ending. Save it, use Tools | Code Snippet Manager | Import and then import it.