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?
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?
Snippets usually refer to code snippets which you see in your intellisense dropdown (or Right click > Insert Snippet
such as SurroundsWith
, forEach
etc.). 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.aspx
and folders (App_Code
etc) 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 forEach
is 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.
© 2022 - 2024 — McMap. All rights reserved.