How sort a System.Collections.Generic.List in VB.Net?

前端 未结 4 1368
悲&欢浪女
悲&欢浪女 2021-01-31 09:23

I using a genric list(m_equipmentList ) which is collection of objects (Schedule_Payitem).
How can sort list according to a proerty of child object ?

Dim m_         


        
4条回答
  •  青春惊慌失措
    2021-01-31 09:50

    I don't know vb.net so I did it in C#

    m_equipmentList.Sort(
       (payItem1,payItem2)=>payItem1.ResourceID.CompareTo(payItem2.ResourceID));
    

    and using the reflector translated it to vb.net hope it helps

    m_equipmentList.Sort(
    Function (ByVal payItem1 As Schedule_Payitem, ByVal payItem2 As Schedule_Payitem) 
        Return payItem1.ResourceID.CompareTo(payItem2.ResourceID)
    End Function)
    

    or you can inherit Schedule_Payitem from IComparable and implement CompareTo and then just call m_equipmentList.Sort()

提交回复
热议问题