發布時間:2020-08-06 12:19 作者:獨孤劍 閱讀:7075
using System; using System.Collections.Generic; using System.Data; using System.Text; namespace ConsoleApp14 { class Program { static void Main(string[] args) { List<Content> list1 = new List<Content>(); list1.Add(new Content { Id = 1, Title = "內容1" }); list1.Add(new Content { Id = 3, Title = "內容3" }); list1.Add(new Content { Id = 2, Title = "內容2" }); list1.Sort(SortCompare); } /// <summary> /// 自定義排序 /// </summary> /// <param name="info1"></param> /// <param name="info2"></param> /// <returns></returns> private static int SortCompare(Content info1, Content info2) { //// Id 從小到大 //return info1.Id.CompareTo(info2.Id); // Id 從大到小 return info2.Id.CompareTo(info1.Id); } } public class Content { public int Id { get; set; } public string Title { get; set; } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞