【问题标题】:Keyboard shortcut for C# Console ClassC# 控制台类的键盘快捷键
【发布时间】:2015-11-20 15:20:33
【问题描述】:

我知道Console.WriteLine() 的快捷方式是键入 cwtab 两次。有谁知道Console.ReadLine() 的捷径是什么?

【问题讨论】:

  • 我怀疑是否有,但如果您安装了 ReSharper,您可以定义自己的模板。
  • 如果不存在就创建自己的sn-p
  • ctrl k ctrl x 可以查看所有sn-ps

标签: c# visual-studio shortcut


【解决方案1】:

将以下内容另存为.snippet并导入(使用cw sn-p作为模板)

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

导入后,可以点击crtab两次得到Console.Readline();

【讨论】:

    【解决方案2】:

    Console.ReadLine() 没有快捷方式(代码 sn-p)。但是,您可以创建自己的。

    这是我从cw修改的sn-p:

    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
        <CodeSnippet Format="1.0.0">
            <Header>
                <Title>rl</Title>
                <Shortcut>rl</Shortcut>
                <Description>Code snippet for Console.ReadLine</Description>
                <Author>Xiaoy312</Author>
                <SnippetTypes>
                    <SnippetType>Expansion</SnippetType>
                </SnippetTypes>
            </Header>
            <Snippet>
                <Declarations>
                    <Literal>
                        <ID>input</ID>
                        <ToolTip>variable for console input</ToolTip>
                        <Default>input</Default>
                    </Literal>
                    <Literal Editable="false">
                        <ID>SystemConsole</ID>
                        <Function>SimpleTypeName(global::System.Console)</Function>
                    </Literal>
                </Declarations>
                <Code Language="csharp"><![CDATA[var $input$ = $SystemConsole$.ReadLine();$end$]]>
                </Code>
            </Snippet>
        </CodeSnippet>
    </CodeSnippets>
    

    只需将其放入您的 sn-p 文件夹即可。我把我的放在那里:

    C:\Users\Xiaoy\Documents\Visual Studio 2015\CodeSnippets\Visual C#\My Code Snippets\rl.sn-p

    当你输入rltab 两次时,你会得到这个:

    var input = Console.ReadLine();
    

    【讨论】:

      【解决方案3】:

      对于使用 VSCode 的任何人,请安装 C# Snippets extension - 它包括许多 sn-ps,包括 Console.ReadLine()。

      【讨论】:

        猜你喜欢
        • 2010-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-30
        • 1970-01-01
        • 2011-04-08
        • 1970-01-01
        • 2011-03-20
        相关资源
        最近更新 更多