0

我正在开发一个控制台应用程序,它通过 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
4

2 回答 2

2

您可以将值存储在 Array 或其他 Collection 中,并使用Array.Sort

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

于 2013-08-01T18:42:43.310 回答
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))

注意:aCountbCountcCount和是您为点击相应按钮dCount而跟踪eCount的五个值。Integer

Dim sortedListButtonCount As List(Of ButtonCount) = listButtonCount.OrderBy(Function(c) c.Count).ToList()
于 2013-08-01T18:55:01.697 回答