.我希望List变量能够按照自定义数据类型内部的myDateTime实现升序或降序来排列.
public class ipData { public DateTime myDateTime{ set; get; } public string theIP{ set; get; } } //-------------------------------------------------------------------------- List<ipData> IPList = new List<ipData>(); ipData t1 = new ipData(); ipData t2 = new ipData(); t1.myDateTime=System.DateTime.Now; t1.theIP = "........." t2.myDateTime=System.DateTime.Now; t2.theIP = "........." IPList.Add(t1); IPList.Add(t2);
IPList.OrderBy(x=>x.myDateTime);
IPList.OrderByDescending(x=>x.myDateTime);
List 类中 有个属性,可以自动排序的,比如
List<string> str =new List<string>(); str.Sort("Item");
Item 就是你需要排序的字段,默认是升序好像。