共用方式為


Default 項目 (IntelliSense 程式碼片段)

更新:2007 年 11 月

指定 IntelliSense 程式碼片段之常值 (Literal) 或物件的預設值。

 <Default>     Default value </Default>

屬性和項目

下列章節將說明屬性 (Attribute)、子項目和父項目。

屬性

無。

子項目

無。

父項目

項目

描述

Literal

定義可以編輯的程式碼片段的常值欄位。

Object

定義可以編輯的程式碼片段的物件欄位。

文字值

需要文字值。

此文字可指定常值或物件的預設值,這個值將會填入可編輯之程式碼片段的欄位中。

範例

下列程式碼片段會示範含有 SQL 預設值的常值以及含有 Connection 預設值的物件。Default 項目的文字值表示在將程式碼片段插入專案時的常值或物件。

<CodeSnippets xmlns="https://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Create a data adapter</Title>
            <Description>Creates a SqlDataAdapter object.</Description>
            <Author>Microsoft Corporation</Author>
            <Shortcut>createadapter</Shortcut>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>SQL</ID>
                    <ToolTip>Replace with a SQL connection string.</ToolTip>
                    <Default>"SQL connection string"</Default>
                </Literal>
                <Object>
                    <ID>Connection</ID>
                    <Type>System.Data.SqlClient.SqlConnection</Type>
                    <ToolTip>Replace with a connection object in your application.</ToolTip>
                    <Default>dcConnection</Default>
                </Object>
            </Declarations>
            <Code Language="CSharp">
                <![CDATA[
                    daCustomers = new SqlClient.SqlDataAdapter();
                    selectCommand = new SqlClient.SqlCommand($SQL$);
                    daCustomers.SelectCommand = selectCommand;
                    daCustomers.SelectCommand.Connection = $Connection$;
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

請參閱

概念

程式碼片段結構描述參考