visual-studio Visual Studio 立即窗口:如何查看前 100 个以上的项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1785745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Immediate window: how to see more than the first 100 items
提问by DOK
I am trying to see the properties of an object with over 300 properties in the Immediate Window of Visual Studio 2005. Only the first 100 items are displayed, followed by this caption:
我试图在 Visual Studio 2005 的即时窗口中查看具有 300 多个属性的对象的属性。仅显示前 100 个项目,然后是此标题:
< More... (The first 100 of 306 items were displayed.) >
I am trying to see the rest of the items, but can't figure it out.
我正在尝试查看其余项目,但无法弄清楚。
I realize that I could see these in a Watch window, but that's not the same.
我意识到我可以在 Watch 窗口中看到这些,但那是不一样的。
采纳答案by Gene Whitaker
I know this is way late. However, If you add your object to the watch window. Expand the properties, where all are displayed. Then Ctrl-A and Copy. You can then paste in excel to get an organized list of properties and their values.
我知道这已经很晚了。但是,如果您将对象添加到监视窗口。展开显示所有属性的属性。然后 Ctrl-A 和复制。然后,您可以粘贴到 excel 中以获得有组织的属性及其值列表。
回答by Ian Routledge
I know this was almost to years ago, but I came up against this today. Sometimes its useful to see the list in the immediate window rather than looking in the watch window. You can easily see more results than the first 100 by using:
我知道这几乎是几年前的事了,但今天我遇到了这个问题。有时在即时窗口中查看列表而不是在监视窗口中查看很有用。您可以使用以下命令轻松查看比前 100 个更多的结果:
yourList.Skip(100).ToArray()
Which really doesn't take long to write and works well - was useful for me.
这真的不需要很长时间编写并且效果很好 - 对我很有用。
Update: As pointed out in the comments below, this answer is actually wrong and applicable ONLY to collections and NOT to objects with lots of properties. I'm leaving it here as lots of people seem to have found it useful.
更新:正如下面的评论中所指出的,这个答案实际上是错误的,仅适用于集合,不适用于具有大量属性的对象。我把它留在这里是因为很多人似乎发现它很有用。
回答by Gabriel McAdams
The immediate window was designed to be a quick view tool. If you want to see more detail, you will have to view it in either the Watch Window or the Quick Watch Window.
即时窗口被设计为一个快速查看工具。如果您想查看更多细节,则必须在 Watch Window 或 Quick Watch Window 中查看。
Another option is to write a Visual Studio AddIn that operates similarly to the Immediate Window, but has more options.
另一种选择是编写一个 Visual Studio AddIn,其操作类似于立即窗口,但具有更多选项。
回答by John
I always create an extension method to export objects to xml when debugging like this. It's very useful for troubleshooting object data. Here is what I use:
在像这样调试时,我总是创建一个扩展方法来将对象导出到 xml。它对于排除对象数据的故障非常有用。这是我使用的:
public static void SerializeToXML(this object entity)
{
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(entity.GetType());
System.IO.StreamWriter file = new System.IO.StreamWriter(string.Format(@"{0}\{1}.xml", Directory.GetCurrentDirectory(), entity.GetType().Name));
writer.Serialize(file, entity);
file.Close();
}
It's not 100% full proof, but most of the time it is perfect. It will create an xml file in the application directory with the objects name as the file name. In the immediate window you can just type the object name then .SerializeToXML().
这不是 100% 完全证明,但大多数时候它是完美的。它将在应用程序目录中创建一个以对象名称作为文件名的 xml 文件。在即时窗口中,您只需输入对象名称,然后输入 .SerializeToXML()。
so: myList.SerializeToXML()
所以:myList.SerializeToXML()

