Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a(,) As Integer = {{5, 6}, {1, 3}, {8, 9}, {72, 1}, {63, 4}}
Dim Temp As Integer
Dim i As Integer
Dim j As Integer
Dim x As Integer
Dim y As Integer
'显示排序前的数据
Label1.Text = "排序前数据:" &vbCrLf
For i = 0 To 4
Label1.Text = Label1.Text &a(i, 0) &" " &a(i, 1) &vbCrLf
Next
For i = 0 To 3
For j = i + 1 To 4
If a(i, 0) >a(j, 0) Then
Temp = a(i, 0)
a(i, 0) = a(j, 0)
a(j, 0) = Temp
Temp = a(i, 1)
a(i, 1) = a(j, 1)
a(j, 1) = Temp
End If
Next
Next
'显示排序前的数据
Label2.Text = "排序后数据:" &vbCrLf
For i = 0 To 4
Label2.Text = Label2.Text &a(i, 0) &" " &a(i, 1) &vbCrLf
Next
'把第3行元素赋予X,Y
x = a(2, 0)
y = a(2, 1)
'输出X,Y
Label3.Text = "X=" &x &vbCrLf &"Y=" &y
End Sub
// 数据排序(该步骤仅对默认视图进行排序)datatable.DefaultView.Sort = "序号"
// 把数据视图更新到数据结果集 (将默认视图的已经排序的内容复制到table中)
datatable = datatable.DefaultView.ToTable()
参考资料:http://www.dearboy.cn/a/201407/472.html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)