【发布时间】:2016-06-02 05:44:27
【问题描述】:
我正在学习 VB.NET,我想知道通过 Hashtable 中的排序值获取键的更好方法
这是我构建的解决方案
Dim int_Value As Integer() = New Integer() {-9, 2, 8, 6, 8, 1, -9}
Dim int_Key As Integer() = New Integer() {1, 2, 3, 4, 5, 6, 7}
Dim Dum_Int(int_Key.Length) As Integer
Dim STORE_KEYS As New ArrayList
Array.Copy(int_Value, Dum_Int, Dum_Int.Length - 1)
Array.Sort(Dum_Int)
Array.Reverse(Dum_Int)
For I = 0 To Dum_Int.Length - 1
For II = 0 To int_Value.Length - 1
If Dum_Int(I) = int_Value(II) Then
STORE_KEYS.Add(int_Key(II))
int_Value(II) = Integer.MaxValue
End If
Next
Next
我得到了类似的输出..
''输出''
- (0) 3 {整数} 对象
- (1) 5 {Integer} 对象
- (2) 4 {Integer} 对象
- (3) 2 {Integer} 对象
- (4) 6 {整数} 对象
- (5) 1 {Integer} 对象
- (6) 7 {整数} 对象
我假设我有 Hashtable。
我创建了两个数组并从哈希表中存储键(int_Key)和值(Int_Value)
然后我将 Value(Int_Value) 数组复制到 Dum_Int 以对值进行排序
每当我在排序数组和原始值数组之间找到匹配的 int 值时
我存储在 STORE_KEYS(arraylist) 中,并将 Max Int 值插入原始数组以防止重叠问题。
但是,有什么办法可以改进这种方法吗?
我不认为更好的排序算法无助于简化这种方法。
您能否提供任何提示来简化此方法?
谢谢
【问题讨论】:
-
除非您使用的是早于 2005 的 VB 版本,否则您不应使用
Hashtable或ArrayList。您应该改用Dictionary和List。 -
我不明白你想达到什么目的。
标签: arrays vb.net sorting hashtable