Unlike cw (for Console.WriteLine) there is no shortcut available for Console.ReadLine in Visual Studio 2019. In this short post I will show you how I’ve created a snippet that binds cr to Console.ReadLine.

1. Save the following as .snippet somewhere on your computer.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
            <Description>Code snippet for Console.ReadLine</Description>
            <Author>Whoever you want it to be</Author>
                <Literal Editable="false">
            <Code Language="csharp"><![CDATA[$SystemConsole$.ReadLine();]]>

2. Click on Import… and find the .snippet file you just saved

Importing custom snippet in Visual Studio 2019

3. Click Finish

Creating custom snippet in Visual Studio 2019

Now if you type cr and hit tab twice (just like cw) you’ll have your Console.ReadLine. Cool!

Happy coding!

Categorized in:

C#, visual studio, web development,

Last Update: January 26, 2020

Tagged in: