Trying to determine when to use a snippet and when to use a template, since they all seem to be able to accomplish the same thing.
Is one better for performance or such, or are they completely differently and I’m misunderstanding something?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Snippets usually refer to code snippets which you see in your intellisense dropdown (or
Right click > Insert Snippetsuch asSurroundsWith,forEachetc.). They usually span few lines and are used to provide shortcut to repeatedly used code patterns.Templates refer to Item/Project templates which can contain code plus other things such as file structure for a project and more). Think of it as a scaffolding for code file or a project.
E.g. WebSite project templates creates the scaffolding for a typical WebSite by adding files such as
default.aspxand folders (App_Codeetc) when you choose to create a new website project.There is also what is known as T4 templates which are used for code generation. The scope of this goes beyond a handful of lines (which is typically what a snippet would add). You can add code and control logic which makes them way more powerful than snippets. At the same time, writing a T4 template for something like
forEachis a overkill. You also cannot right click and say insert snippet here within the editor.Comparing performance is not relevant here as each is a one time thing. You choose one over either based on what you want to do with it.