从通用列表中获取最大和更大的对象

时间:2013-04-17 18:03:12

标签: .net vb.net generic-list

我有一个System.Version个对象列表,

我需要获得列表中最好的版本以及大于指定版本的版本

Dim versions As New List(Of Version)
versions = LoadVersions()

' Get the greatest version object
Dim greatestVersion = versions.Greatest() '???

' Get version objects greater than the specified one
Dim ver = New Version("2.0.1.0")
Dim greaterVersions As List(Of Version) = version.GreaterThan(ver) '???

这样做的好方法是什么?

2 个答案:

答案 0 :(得分:5)

最伟大的版本:

Dim greatestVersion = versions.Max()

大于所选版本:

Dim greaterVersions = versions.Where(Function (x) x > ver)

阅读MSDN LINQ reference

答案 1 :(得分:1)

这就是我要解决的问题,后来我改进了@Konrad建议:

'Greatest version
Dim maxver = versions.Max(Of Version)(Function(ver As Version) ver)

'Greater versions
Dim currentVersion As New Version("2.0.1.0")
Dim geaterVers = versions.Where(Function(ver As Version) ver > currentVersion)