gpt4 book ai didi

c# - 如何让 ToString() 出现在 Debug 中

转载 作者:可可西里 更新时间:2023-11-01 07:49:31 25 4
gpt4 key购买 nike

我想让 ToString() 在 Debug模式下为我控制的类显示。

如果这是当您将鼠标悬停在变量上时首先显示的内容,那就太好了。这个有属性吗?

最佳答案

标记你的类(class)

[System.Diagnostics.DebuggerDisplay("{ToString()}")]

测试:

[System.Diagnostics.DebuggerDisplay("{ToString()}")]
class MyClass
{
private string _foo = "This is the text that will be displayed at debugging"

public override string ToString()
{
return _foo;
}
}

现在,当您将鼠标悬停在一个变量上时,它会显示This is the text that will be displayed at debugging

关于c# - 如何让 ToString() 出现在 Debug 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6829032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com