DebuggerDisplayAttribute.Name 屬性

定義

取得或設定顯示於偵錯工具變數視窗中的名稱。Gets or sets the name to display in the debugger variable windows.

public:
 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
public string? Name { get; set; }
member this.Name : string with get, set
Public Property Name As String

屬性值

String

要顯示在偵錯工具變數視窗中的名稱。The name to display in the debugger variable windows.

範例

下列程式碼範例會將每個索引鍵的名稱和值顯示在偵錯工具變數視窗中。The following code example causes the name and value of each key to be displayed in the debugger variable windows. 當未套用屬性時,會顯示索引和數值型別 (例如: "[0] {KeyValuePairs}" ) 。When the attribute is not applied, the index and value type are displayed (for example: "[0] {KeyValuePairs}"). 套用屬性時,會顯示索引鍵和其值的名稱 (例如,如果第一個索引鍵是 "one" 且其值為1,則顯示為: "1 1" ) 。When the attribute is applied, the name of the key and its value are displayed (for example, if the first key is "one" and its value is 1, the display is: "one 1"). 這個程式碼範例是針對類別提供之較大範例的一部分 DebuggerDisplayAttributeThis code example is part of a larger example provided for the DebuggerDisplayAttribute class.

[DebuggerDisplay("{value}", Name = "{key}")]
ref class KeyValuePairs
{
private:
    IDictionary^ dictionary;
    Object^ key;
    Object^ value;

public:
    KeyValuePairs(IDictionary^ dictionary, Object^ key, Object^ value)
    {
        this->value = value;
        this->key = key;
        this->dictionary = dictionary;
    }
};
[DebuggerDisplay("{value}", Name = "{key}")]
internal class KeyValuePairs
{
    private IDictionary dictionary;
    private object key;
    private object value;

    public KeyValuePairs(IDictionary dictionary, object key, object value)
    {
        this.value = value;
        this.key = key;
        this.dictionary = dictionary;
    }
}
<DebuggerDisplay("{value}", Name := "{key}")>  _
Friend Class KeyValuePairs
    Private dictionary As IDictionary
    Private key As Object
    Private value As Object
    
    
    Public Sub New(ByVal dictionary As IDictionary, ByVal key As Object, ByVal value As Object) 
        Me.value = value
        Me.key = key
        Me.dictionary = dictionary

    End Sub
End Class

備註

此值可包含大括弧 ( {和} ) 。The value can contain curly braces ({ and }). 成對大括弧內的文字會評估為欄位、屬性或方法的名稱。Text within a pair of braces is evaluated as the name of a field, property, or method.

適用於