Creating Console.ReadLine Snippet in Visual Studio 2019

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">
        <Header>
            <Title>cr</Title>
            <Shortcut>cr</Shortcut>
            <Description>Code snippet for Console.ReadLine</Description>
            <Author>Whoever you want it to be</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal Editable="false">
                    <ID>SystemConsole</ID>
                    <Function>SimpleTypeName(global::System.Console)</Function>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[$SystemConsole$.ReadLine();]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

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!

6 thoughts on “Creating Console.ReadLine Snippet in Visual Studio 2019”

  1. Thanks A lot Dear Sir for Console.ReadLine snippet. I am 52 Years Old Man. and interested in learning Csharp and I am trying to understand programming logic by looking different YouTube Tutorials. any suggestion for me dear sir . Hope you will reply me. Thanks in advance

    1. Hi Muhammad,
      Thanks for stopping by.
      YouTube has tons of useful content regarding C# and programming in general.
      Another great place that you should definitely check out is Microsoft’s official documentation which is probably your best bet as it’s updated regularly and written by experts.
      Here is the their website: https://docs.microsoft.com/en-us/dotnet/csharp/

Leave a Reply

Your email address will not be published. Required fields are marked *