Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Method tutorial for custom sorting of list generics

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "list generic custom sorting method tutorial", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn the "list generic custom sorting method tutorial" bar!

The copy code is as follows:

Static void Main (string [] args)

{

Employee employee = new Employee ()

/ / set the initial value

List employeeList = new List ()

EmployeeList.Add (new Employee () {EmpId = "001", EmpName = "Tony"})

EmployeeList.Add (new Employee () {EmpId = "002", EmpName = "Mack"})

EmployeeList.Add (new Employee () {EmpId = "003", EmpName = "Jon"})

EmployeeList.Add (new Employee () {EmpId = "004", EmpName =" Dawei "})

EmployeeList.Add (new Employee () {EmpId = "005", EmpName = "Jack"})

EmployeeList.Add (new Employee () {EmpId = "006", EmpName =" Abby "})

EmployeeList.Add (new Employee () {EmpId = "007", EmpName = "Carrie"})

/ / specify pre-sort elements

List toSortList = new List ()

ToSortList.Add (new Employee () {EmpId = "003", EmpName = "Jon"})

ToSortList.Add (new Employee () {EmpId = "005", EmpName = "Jack"})

ToSortList.Add (new Employee () {EmpId = "007", EmpName = "Carrie"})

/ / Custom sort delegation

EmployeeList.Sort ((Employee x, Employee y) = > (toSortList.Count (e = > e.EmpId = = y.EmpId)-toSortList.Count (e = > e.EmpId = = x.EmpId)

}

Public class Employee

{

Public string EmpId

{

Get

Set

}

Public string EmpName

{

Get

Set

}

}

After sorting, the elements in the original list are sorted according to 001jue 002j003, and the elements are sorted as 003005007001002004. Rank the specified 003, 005, 007 at the front of the List

Thank you for your reading, the above is the content of the "list generic Custom sorting method tutorial". After the study of this article, I believe you have a deeper understanding of the list generic Custom sorting method tutorial, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report