DebuggerDisplayAttribute.Name 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定顯示於偵錯工具變數視窗中的名稱。
public:
property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
C#
public string Name { get; set; }
C#
public string? Name { get; set; }
member this.Name : string with get, set
Public Property Name As String
要顯示在偵錯工具變數視窗中的名稱。
下列程式代碼範例會使調試程式變數視窗中顯示每個索引鍵的名稱和值。 未套用屬性時,索引和實值類型會顯示 (例如:“[0] {KeyValuePairs}”) 。 套用屬性時,索引鍵的名稱及其值會顯示 (例如,如果第一個索引鍵是 “one”,而其值為 1,則顯示方式為:“一 1”) 。 此程式代碼範例是提供給 類別之較大範例的 DebuggerDisplayAttribute 一部分。
[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;
}
};
C#
[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
值可以包含大括弧 ({ 和 }) 。 一對大括號內的文字會評估為字段、屬性或方法的名稱。
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |