C # Sort sorting

Source: Internet
Author: User
# Region: Class userinfo: icomparable <userinfo> {public int ID {Get; set;} public int age {Get; set;} public string name {Get; set;} public int compareto (userinfo other) {If (this. age> Other. age) return 1; Return-1 ;}// call list <userinfo> lst = new list <userinfo> () {New userinfo () {id = 1, age = 19, name = "Zhang San"}, new userinfo () {id = 2, age = 17, name = "Li Si"}, new userinfo () {id = 3, age = 20, name = "Wang Wu" }}; lst. sort (); For (INT I = 0; I <lst. count; I ++) {console. write (LST [I]. name + ":" + lst [I]. age + "<") ;}# endregion # region implements the sort sorting class userinfo_sortbyid: icomparer <userinfo> {public int compare (userinfo X, userinfo y) {If (X. ID <Y. ID) return 1; Return-1 ;}list <userinfo> lst = new list <userinfo> () {New userinfo () {id = 1, age = 19, name = "Zhang San"}, new userinfo () {id = 2, age = 17, name = "Li Si"}, new userinfo () {id = 3, age = 20, name = "Wang Wu" }}; lst. sort (New userinfo_sortbyid (); For (INT I = 0; I <lst. count; I ++) {console. write (LST [I]. name + ":" + lst [I]. age + "<") ;}# endregion

 

C # Sort sorting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.