问题描述
我在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
推荐答案
<DebuggerDisplay("{CustomerId}: {CustomerName}")>
Public Class Customer
...
End Class
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[^]
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调试集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!