2013-02-10 107 views
0

定製類的名單我有一個自定義類排序使用LINQ

Class Item 
    Public item As String 
    Public Descrip As String 
    Public price As String 
    Public Bin As String 
    Public Total As Decimal 
    Public Qty As Integer 
End Class 

現在我有另一個類

Public Class Default3 
    Inherits System.Web.UI.Page 

    Dim c As Int16 = 0 
    Dim Item3 As New Item 
    Dim Item2 As New List(Of Item) 

現在我將在項目2型項目的項目

Item3.Item = String.Format(record(0)) ' Field "Item" 
Item3.Descrip = String.Format(record(1)) ' Field "Descrip" 
Item3.price = String.Format(record(2)) ' Field "Price" 
Item3.Bin = String.Format(record(3))  ' Field "Bin" 

Item2.Add(Item3) 

現在我怎麼能根據Item3.Bin排序Item2中的元素? 感謝

回答

0

使用OrderBy

Item2 = Item2.OrderBy(Function(x) x.Bin).ToList() 

或者你也可以使用Sort

Item2.Sort(Function(x, y) x.Bin.CompareTo(y.Bin))