简体   繁体   English

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

[英]Using Array Sort <strings> <integers>

Im working on a console application which sends and receives data through a WinSock control. 我在一个控制台应用程序上工作,该应用程序通过WinSock控件发送和接收数据。 for each incremental stream that gets added to the buffer i have generated an array list and appended incoming integral address (IPv4) from the stream. 对于添加到缓冲区的每个增量流,我已经生成了一个数组列表并从流中添加了传入的整数地址(IPv4)。 however, while listing the data in another control, it appears in Unsorted manner. 但是,在将数据列在另一个控件中时,它将以未排序的方式显示。

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

You could store the values in an Array, or other Collection, and use Array.Sort . 您可以将值存储在Array或其他Collection中,并使用Array.Sort

If you store them in separate variables then you would need to write the code that sorts them. 如果将它们存储在单独的变量中,那么您需要编写对它们进行排序的代码。

Assuming you have 5 integer values for each of the button click counts, then you can order them in ascending order like this: 假设每个按钮点击次数有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))

Note: aCount , bCount , cCount , dCount and eCount are the five Integer values you are keeping track of for clicks of the respective buttons. 注意: aCountbCountcCountdCounteCount是您跟踪各个按钮点击的五个Integer数值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM