简体   繁体   English

在Visual Studio 2013中使用快捷方式

[英]Using shortcuts in visual studio 2013

Using the following and pressing the tab key visual studio writes the properties for us. 使用以下内容并按Tab键,Visual Studio会为我们编写属性。

//prop
public int MyProperty { get; set; }
//propg
public int MyProperty { get; private set; }
//propfull
private int myVar;

public int MyProperty
{
    get { return myVar; }
    set { myVar = value; }
}

As you can see all of them are int by default is there a way to change the shortcut to allow different data types 如您所见,默认情况下它们都是int,有一种方法可以更改快捷方式以允许不同的数据类型

I use Visual Studio 2012 and all my C# code snippets under my 我使用Visual Studio 2012和我所有的C#代码段

C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC#\\Snippets\\1033\\Visual C#\\ C:\\ Program Files(x86)\\ Microsoft Visual Studio 11.0 \\ VC#\\ Snippets \\ 1033 \\ Visual C#\\

folder. 夹。 For example, when you edit prop.snippet , you will get like; 例如,当您编辑prop.snippet ,您将得到:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>prop</Title>
            <Shortcut>prop</Shortcut>
            <Description>Code snippet for an automatically implemented property
Language Version: C# 3.0 or higher</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Property type</ToolTip>
                    <Default>int</Default>
                </Literal>
                <Literal>
                    <ID>property</ID>
                    <ToolTip>Property name</ToolTip>
                    <Default>MyProperty</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[public $type$ $property$ { get; set; }$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

As you can see, it is defined <Default>int</Default> as a default. 如您所见,它被定义为<Default>int</Default>作为默认值。 You can change it which type as you want. 您可以根据需要更改它的类型。

You can find them in Code Snippet Manager as well; 您也可以在代码片段管理器中找到它们;

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM