如何获取ToString()在调试中显示 [英] How to get ToString() to show up in Debug
本文介绍了如何获取ToString()在调试中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让ToString()在调试模式下为我控制下的类显示。
I'd like to get ToString() to display for a class under my control in debug mode.
如果这是当您将鼠标悬停在变量上时首先显示的东西,那就太好了。
It'd be nice if this was the first thing to show up when you hover over a variable with the mouse. Is there an attribute for this?
推荐答案
标记您的班级
[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;
}
}
现在,当您将鼠标悬停在变量上时将显示这是将在调试时显示的文本
。
Now when you hover over a variable with the mouse it will show This is the text that will be displayed at debugging
.
这篇关于如何获取ToString()在调试中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文