所以我的项目是分析图表。我想找到算法来查找最大和最小数据。我在每个图中得到不同的max值。所以我想找到平均值或高频率最大值。
PLEASE LOOK AT THIS LINK PICTURE
我写信是为了找到最大数据。这是我的代码
Private Function FindMaxDataTableValue(ByRef dt As DataTable) As Integer
Dim currentValue As Integer, maxValue As Integer
Dim dv As DataView = dt.DefaultView
For c As Integer = 0 To dt.Columns.Count - 1
dv.Sort = dt.Columns(c).ColumnName + " DESC"
currentValue = CInt(dv(0).Item(c))
If currentValue > maxValue Then maxValue = currentValue
Next
Return maxValue
End Function
答案 0 :(得分:1)
如果您可以使用LINQ(.NET 3.5+),那么您可以使用Max
(和Min
,Average
)函数:
Private Function FindMaxDataTableValue(ByVal dt As DataTable) As Integer
' Find the max value for each column
Dim maximums = (
From c In dt.Columns.Cast(Of DataColumn)()
Select dt.AsEnumerable().Max(Function(x) x.Field(Of Integer)(c))
).ToList()
' Return the highest of the maximums
Return maximums.Max()
End Function