VB.NET字符串数组排序

VB.NET编程实现

Public Class Form1
    '声明一个包含6个元素的字符串数组Student
    Dim Student(5) As String
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '对数组元素赋值
        Dim i As Integer
        Student(0) = "张三"
        Student(1) = "王刚"
        Student(2) = "李想"
        Student(3) = "李华"
        Student(4) = "陈晨" : Student(5) = "钱进"
        '在文本框中进行分行显示,每个元素占一行。vbCrLf:回车换行
        For i = 0 To 5
            TextBox1.Text &= Student(i) & vbCrLf
        Next
    End Sub

    Private Sub btnSort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSort.Click
        '对数组进行排序
        Dim a As String
        Array.Sort(Student)
        '在文本框中显示排序后的元素
        For Each a In Student
            TextBox2.Text &= a & vbCrLf
        Next
    End Sub
End Class

排序前

在这里插入图片描述

排序后

在这里插入图片描述

发布了570 篇原创文章 · 获赞 1179 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/weixin_43896318/article/details/104414948
今日推荐