gpt4 book ai didi

vb.net - 查找 VB.Net DataTable 的最大值

转载 作者:行者123 更新时间:2023-12-05 08:24:23 27 4
gpt4 key购买 nike

我被这个问题难倒了。我有一个相当大的 (~1500 x ~1000) 正整数和负整数数据表, 我是从 .csv 文件中获取的。对于我的程序,我需要找到整个表的最大值,而不仅仅是在单个行或列中。最理想的情况是,代码应该简短而有趣,但情况并非总是如此 ;)。

我的 DataTable 的名称是 BeamMap,我试图返回 MaxValue 的值(已声明为整数)。我可以根据要求发布用于创建 DataTable 的代码。

额外学分:(不是真的)

有没有办法快速找到所述最大值的位置(即,行,列)?到目前为止,我见过的所有示例都是逐个单元地检查预定值,这对于我拥有的数据点数量而言效率相当低。

最佳答案

您还可以使用 Compute("MAX(columnName),"") 方法在列上查找最大值

Private Function FindMaxDataTableValue(ByRef dt As DataTable) As Integer

Dim currentValue As Integer, maxValue As Integer
maxValue = 0

For c As Integer = 0 To dt.Columns.Count - 1
currentValue = dt.Compute("MAX(c)", "")
If currentValue > maxValue Then maxValue = currentValue
Next
Return maxValue

End Function

关于vb.net - 查找 VB.Net DataTable 的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11116445/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com