Prep Code Snippets

  1. 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.
  2. What are class and class associated snippet commands? (hint: 4)
    • class
    • ctor (constructor)
    • prop
    • propg (get only)
  3. What are the looping snippet commands? (hint: 4)
    • 1. for
    • 2. foreach
    • 3. do
    • 4. while
  4. 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())
  5. 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)
  6. 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?

    This will give you intellisense values for C#, Testing, MVC, and others including those for loops, events, delegates, classes, and much more.
  7. 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
  8. What shortcut is used to select the current line? How about those above or below?
  9. 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.
  10. Give the basic XML parts of a code snippet file.
    • <?xml version="1.0" encoding="utf-8"?> 
    • <CodeSnippets xmlns="">
    • <CodeSnippet Format="1.0.0">
    • <Header>
    • <Title>Method</Title>
    • <Author>Matthew</Author>
    • <Description>Creates a public method template with a thrown exception.</Description>
    • <Shortcut>method</Shortcut>
    • </Header>
    • <Snippet>
    • <Code Language="CSharp">
    • <![CDATA[public void MyMethod()
    • {
    • throw new NotImplementedException();
    • }]]>
    • </Code>
    • </Snippet>
    • </CodeSnippet>
    • </CodeSnippets>
Card Set
Prep Code Snippets
Questions on code snippets, shortcuts, and program setup instructions for solutions and projects.