VB2005 在 ListOf 结构中查找/搜索

发布于 2024-12-10 07:24:35 字数 586 浏览 0 评论 0原文

VB2005:我花了几个小时寻找一个很好的例子,我找到了一些,但不幸的是它们是针对 VB2008+ 的。我目前正在使用 VB2005,因此在该版本中这似乎更难做到。

我有一个点的类

Public Class cPoint
    Public Speed As Integer
    Public Alt As Integer
    Public Status As String = ""
    Public Err As String = ""
End Class

,我用 MyPoints=List(of cPoint) 填充点列表。现在我需要做的就是找到具有提供的速度和 alt 的第一个匹配项。我尝试过

Dim p As cPoint = MyPoints.Find(Function(item As cPoint) item.Speed = 85)

但这在 VB2005 中不起作用,更不用说使用超过 1 个过滤器了。我似乎找不到一个在 VB2005 中工作的好例子。我可以遍历列表,但它很大而且效率不高。有什么关于如何在 VB2005 中做到这一点的提示吗?

~agp

VB2005: I've been looking for several hours on a good example and i found some but unfortunately they are for VB2008+. Im currently working in VB2005 so it seems like this was harder to do in that release.

I have a class for a point

Public Class cPoint
    Public Speed As Integer
    Public Alt As Integer
    Public Status As String = ""
    Public Err As String = ""
End Class

I populate a list of points with MyPoints=List(of cPoint). Now all i need to do is find the first match with a supplied speed and alt. I tried

Dim p As cPoint = MyPoints.Find(Function(item As cPoint) item.Speed = 85)

But that doesn't work in VB2005 much less work with more than 1 filter. I just cant seem to find a good example that works in VB2005. I could iterate through the list but its kind of big and not very efficient. Any tips on how i can do this in VB2005?

~agp

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没︽人懂的悲伤 2024-12-17 07:24:35

VB.Net 2005 缺乏 lambda 支持,因此这种查询方式不起作用。最简单的版本是使用 For Each 循环手动迭代。

My p As cPoint = Nothing
For Each item in MyPoints 
  If item.Speed = 85 Then
    p = item
    Exit For 
  End If
Next

VB.Net 2005 lacks lambda support hence that style of query won't work. The simplest version that will is to manually iterate with a For Each loop.

My p As cPoint = Nothing
For Each item in MyPoints 
  If item.Speed = 85 Then
    p = item
    Exit For 
  End If
Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文