vb.net数组排序 vbscript 数组

编写一个 VB.NET 程序,产生 100 个 100 以内的随机数,将他们从大到小排序后输出Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 100'给数组a一百个元素赋值vb.net数组排序,并换每行十个数字输出来窗体上
a(i) = Int(Rnd * 101)
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
Print
Print
For i = 100 To 2 Step -1'用冒泡排序法对数组进行排序
For j = 1 To i - 1
If a(j)a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To 100'输出排好序vb.net数组排序的数组
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
End Sub
VB.net 数组怎么按任意元素的顺序排序输出你直接传一个数组进去vb.net数组排序 , 而且是一个结构体数组vb.net数组排序 , array.sort怎么知道根据结构中vb.net数组排序的哪一个属性进行排序?放一个c#的代码你看看,VB和C#很相似的
class Program
{
static void Main(string[] args)
{
People[] p = new People[3]
{
new People{name="张三"},
new People{name="李四"},
new People{name="张二名"}
};
//重点传一个实现了IComparer接口的类进去,告诉Array.Sort怎么排序
Array.Sort(p, new PeopleCompare());
foreach (var item in p)
{
Console.WriteLine(item.name);
}
Console.ReadKey();
}
}
//People结构体,换成类一样的
public struct People
{
public string name { get; set; }
}
//实现了IComparer接口的类
public class PeopleCompare : IComparer
{
public int Compare(object x, object y)
{
People p1 = (People)x ;
People p2 = (People)y;
return p1.name.CompareTo(p2.name);
}
}
VB.NET数组的排序法?如果vb.net数组排序你是从vb6刚过渡上vb 。net,建议还是用冒泡排序法 , 容易理解 。
如果你正努力学习vb 。net的方法,推荐一个例子如下vb.net数组排序:
Imports System
Imports System.Collections
Public Class SamplesArray
Public Class myReverserClass
Implements IComparer
' Calls CaseInsensitiveComparer.Compare with the parameters reversed.
Function Compare(x As Object, y As Object) As Integer _
Implements IComparer.Compare
Return New CaseInsensitiveComparer().Compare(y, x)
End Function 'IComparer.Compare
End Class 'myReverserClass
Public Shared Sub Main()
' Creates and initializes a new Array and a new custom comparer.
Dim myArr As [String]() ={"The", "QUICK", "BROWN", "FOX", "jumps", "over", "the", "lazy", "dog"}
Dim myComparer = New myReverserClass()
' Displays the values of the Array.
Console.WriteLine("The Array initially contains the following values:")
PrintIndexAndValues(myArr)
' Sorts a section of the Array using the default comparer.
Array.Sort(myArr, 1, 3)
Console.WriteLine("After sorting a section of the Array using the default comparer:")
PrintIndexAndValues(myArr)
' Sorts a section of the Array using the reverse case-insensitive comparer.
Array.Sort(myArr, 1, 3, myComparer)
Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")
PrintIndexAndValues(myArr)
' Sorts the entire Array using the default comparer.
Array.Sort(myArr)
Console.WriteLine("After sorting the entire Array using the default comparer:")
PrintIndexAndValues(myArr)
' Sorts the entire Array using the reverse case-insensitive comparer.
Array.Sort(myArr, myComparer)
Console.WriteLine("After sorting the entire Array using the reverse case-insensitive comparer:")

推荐阅读