使用数组排序<strings> <integers> </integers> </strings>

时间:2013-08-01 18:29:12

标签: .net

我正在处理一个通过WinSock控件发送和接收数据的控制台应用程序。对于添加到缓冲区的每个增量流,我已经生成了一个数组列表并从流中添加了传入的整数地址(IPv4)。但是,在将数据列在另一个控件中时,它将以未排序的方式显示。

Private Sub clrHandler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clrHandler.Click
dim clrReckon as Integer
clrReckon = PostCLRCount
PostCLRCount += 1

2 个答案:

答案 0 :(得分:2)

您可以将值存储在数组或其他集合中,并使用Array.Sort

如果将它们存储在单独的变量中,则需要编写对其进行排序的代码。

答案 1 :(得分:0)

假设每个按钮点击次数有5个整数值,那么你可以按照这样的升序排序:

Public Class ButtonCount
Private m_Name As String
    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set
            m_Name = Value
        End Set
    End Property

    Private m_Count As Integer
    Public Property Count() As Integer
        Get
            Return m_Count
        End Get
        Set
            m_Count = Value
        End Set
    End Property

    Public Sub New(name As String, count As Integer)
        Name = name
        Count = count
    End Sub
End Class

Dim listButtonCount As New List(Of ButtonCount)()
listButtonCount.Add(New ButtonCount("A", aCount))
listButtonCount.Add(New ButtonCount("B", bCount))
listButtonCount.Add(New ButtonCount("C", cCount))
listButtonCount.Add(New ButtonCount("D", dCount))
listButtonCount.Add(New ButtonCount("E", eCount))

注意:aCountbCountcCountdCounteCount是您跟踪点击次数的五个Integer值各个按钮。

Dim sortedListButtonCount As List(Of ButtonCount) = listButtonCount.OrderBy(Function(c) c.Count).ToList()