我目前正在进行一个项目,该项目实现了List(of T)的使用。我在试着整理名单。
集合基于PDF_Document类。
Public Class PDF_Document
Public FullFilePath As String
Public Property Size As String
Public Property DocNumber As String
Public Property Sequence As String
Public Property Revision As String
End Class当集合被填充时,它应该根据序列号对集合进行排序。001, 002, 003, 004, ...
但是,如何根据该属性对集合进行排序呢?
发布于 2016-04-11 13:19:17
你为什么要存储这样一个数字,如字符串?如果你想播放用前导零格式化的数字,当你播放它时,格式化它,f.e。使用sequence.ToString("D3"),但不要将其存储为字符串。
如果要对原始列表进行排序,可以使用List(Of T).Sort
pdfList.Sort(Function(pdf1, pdf2)
Return pdf1.Sequence.CompareTo(pdf2.Sequence)
End Function)如果不想修改原始列表,可以使用LINQ:
Dim ordered = From pdf In pdfList Order By pdf.Sequence您可以使用ToList,F.E.创建一个新的列表:
Dim orderedPdfList = ordered.ToList()否则,您总是必须将字符串解析为Int32。
Dim ordered = From pdf In pdfList Order By Int32.Parse(pdf.Sequence)https://stackoverflow.com/questions/36549773
复制相似问题