VS 2010调试集合 [英] VS 2010 Debugging collections

查看:117
本文介绍了VS 2010调试集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2010中有一个VB.Net应用程序,该应用程序有很多集合(主要是List(Of something))

我想要做的是一次查看集合中所有项目的特定属性.

例子:

我有一个(客户列表)

我正在搜索此列表以查找与传递给我的客户匹配的一个

找到

I have a VB.Net application in VS2010 that has a lot of collections (mostly List(Of something))

What I want to be able to do is look at a specific property on all of the items in the collection at once.

An example:

I have a List (Of Customer)

I am searching this list to find the one matching a Customer passed to me

Dim found = From c in customers where c Is searchCustomer Select c



好吧,什么都没找到,我想检查发生了什么.是我有同一个客户的两个实例,还是该客户真的不在集合中?

我的调试策略是查看searchCustomer.CustomerId并检查customers集合中的每个customer对象的CustomerId属性,以查看是否存在匹配项.

我能够找到的唯一方法是

监视客户(0).CustomerId..customers(99).CustomerId

键入时间太长了

或监视集合,并展开节点以查看属性值-这花费的时间太长,而且很烦人

显然,我不能在立即窗口中使用循环-否则我可以做因为i = 0到99 ...? customer(0).Customerid ... Next''之类的东西

我觉得必须要有一种显示customers(x).CustomerId的方法,并让调试器显示每次出现的情况

我的意思是,调试器知道集合中有多少个实例...

因此,PLZ HLP! Urgntz



well, nothing is being found and I want to check what''s going on. Is it that I have two instances of the same customer, or is the customer really not in the collection?

My debugging strategy would be to look at searchCustomer.CustomerId and check each of the customer object in the customers collection for their CustomerId property to see if there is a match or not.

The only ways I have been able to find to do this is

put a watch on customers(0).CustomerId..customers(99).CustomerId

which just takes too long to type

Or put a watch on the collection, and expand nodes looking at the property values - which takes too long and is just annoying

Apparently I can;t use loops in the immediate window - or I could do ''for i = 0 to 99 ... ? customer(0).Customerid ... Next'' or something

I feel there must me a way of showing customers(x).CustomerId and have the debugger show every occurrence

I mean, the debugger knows how many instances there are in the collection ...

So, plz hlp! Urgntz

推荐答案

DebuggerDisplayAttribute添加到您的班级.然后,当您展开列表时,将看到您指定要在调试器中显示的内容.

使用DebuggerDisplay属性
http://msdn.microsoft.com/en-us/library/x810d419.aspx [ ^ ]

您可能还需要打开调试选项在可变窗口中显示对象的原始结构".

此外,可以使用ToString方法来替代ToString,因为有一个调试选项可以在变量窗口中的对象上调用字符串转换函数",但是使用DebuggerDisplayAttribute更好. />
例如:

Add the DebuggerDisplayAttribute to your class. Then when you expand the list, you will see what you specified to display in the debugger.

Using DebuggerDisplay Attribute
http://msdn.microsoft.com/en-us/library/x810d419.aspx[^]

You might also want to turn on the debugging option "Show raw structure of objects in variable windows".

In addition, instead of using the DebuggerDisplayAttribute, you can override the ToString method, since there is a debugging option to "Call string-conversion function on objects in variables windows", but using DebuggerDisplayAttribute is better.

For example:

<DebuggerDisplay("{CustomerId}: {CustomerName}")>
Public Class Customer
   ...
End Class


不是一个调试技巧,但我只是想知道Is的用法.我认为如果要检查是否相等,请使用Equals.这样可以解决问题.
http://msdn.microsoft.com/zh-CN /library/system.object.equals(v=VS.90).aspx [
It''s not a debugging trick, but I just wonder on the use of Is. I think if you want to check for equality, go for Equals. This may solve the problem.
http://msdn.microsoft.com/en-us/library/system.object.equals(v=VS.90).aspx[^]
Dim found = From c in customers where searchCustomer.equals(c) Select c


Is运算符确定两个对象引用是否引用同一对象.但是,它不执行值比较.
http://msdn.microsoft.com/en-us/library/kb136x1y.aspx#Y300 [^ ]


The Is operator determines if two object references refer to the same object. However, it does not perform value comparisons.
http://msdn.microsoft.com/en-us/library/kb136x1y.aspx#Y300[^]


查找单个记录,您是否考虑过使用lambda?



for finding a single record have you not thought about using lambda?

i.e.

dim Customer as CustomerClass = Customers.find(function(p) p.CustomerID = 27)



阅读此 MSDN列表(属于T).查找 [ ^ ]



have a read of this MSDN list(of T).find[^]


这篇关于VS 2010调试集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆