Search code examples
c#visual-studioshortcut

Keyboard shortcut for C# Console Class


I know the shortcut for Console.WriteLine() is type cw and tab twice. Does anyone know what's the short cut for Console.ReadLine() ?


Solution

  • Save the following as a .snippet and import it (used the cw snippet as a template)

    <?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>
    

    Once imported, you can hit cr and tab twice to get Console.Readline();