[英]Using shortcuts in visual studio 2013
使用以下內容並按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; }
}
如您所見,默認情況下它們都是int,有一種方法可以更改快捷方式以允許不同的數據類型
我使用Visual Studio 2012和我所有的C#代碼段
C:\\ Program Files(x86)\\ Microsoft Visual Studio 11.0 \\ VC#\\ Snippets \\ 1033 \\ Visual C#\\
夾。 例如,當您編輯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>
如您所見,它被定義為<Default>int</Default>
作為默認值。 您可以根據需要更改它的類型。
您也可以在代碼片段管理器中找到它們;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.