本文介绍了对数组进行数字排序(VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于记录的降序对记录进行排序:

I want to sort records based on their integer value in descending order:

示例:


name1, 4
name2, 6
name3, 3
name4, 5

应该是重新安排如下:


name2, 6
name4, 5
name1, 4
name3, 3

我尝试使用Array.Sort,但无法正常工作。

I've tried using the Array.Sort but I could not get it working.

一如既往,我感谢您的所有帮助。

As always I appreciate all of your help.

推荐答案

您可以将数据分成两个数组,并使用 array.sort 根据整数排序。

You can split the data into two arrays and use use array.sort to sort based on the integers.

Dim a() As String = {"name1", "name2", "name3", "name4"}
Dim ia() As Integer = {4, 6, 3, 5}
Array.Sort(ia, a)

这将以 ia 。向后迭代数组以获得降序。

This will sort both arrays in ascending order of ia. Iterate the arrays backward to get descending order.

这篇关于对数组进行数字排序(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:20