Gal Segal's Blog

Thoughts of a programmer with a soul

Mar 24

Useful Shortcuts – C# snippets for Visual Studio

Tags:

Shortcut_by_andrearossi

Here are 2 snippets I wrote  that I find missing: one for regions creation and another for “Console.ReadLine()”, which is peculiarly missing, since its’ other brother “Console.WriteLine()” is already there..

Regions snippet:

<CodeSnippets
 xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
 <CodeSnippet Format="1.0.0">
 <Header>
 <Title>Regions Snippet</Title>
 <Author>Gal Segal</Author>
 <Shortcut>reg</Shortcut>
 <Description>Adds regions to class code</Description>
 </Header>
 <Snippet>
 <Code Language="CSharp">
 #region Private Members

 #endregion

 #region Ctor

 #endregion

 #region Properties

 #endregion

 #region Methods

 #region Public

 #endregion

 #region Private

 #endregion

 #endregion
 </Code>
 </Snippet>
 </CodeSnippet>
</CodeSnippets>

Console.ReadLine() Snippet:

<CodeSnippets
 xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
 <CodeSnippet Format="1.0.0">
 <Header>
 <Title>Console.Read() Snippet</Title>
 <Author>Gal Segal</Author>
 <Shortcut>cr</Shortcut>
 <Description>Writes "Console.Read();"</Description>
 </Header>
 <Snippet>
 <Code Language="CSharp">
 Console.Read();
 </Code>
 </Snippet>
 </CodeSnippet>
</CodeSnippets>

Usage

  1. Copy the snippet code, and save it a text file with the extension “.snippet” (like “regions.snippet”).
  2. In Visual Studio, under Tool, click the Code Snippet Manager. (or Ctrl+k, Ctrl+B).
  3. In the Language DropDown, choose C#.
  4. Select one of the folders. (I choose “My Code Snippets”).
  5. Click the “Import” button and select the snippet file.
  6. Try it by typing the shortcut.
  7. You’re done!

Happy Coding :)

Back to top