MyClass tmpClass = new MyClass();
List<MyClass> tmpList = new List<MyClass>();
tmpClass.MyID = “5”;
tmpClass.RandomCode = “555”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “3”;
tmpClass.RandomCode = “333”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “1”;
tmpClass.RandomCode = “111”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “4”;
tmpClass.RandomCode = “444”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “2”;
tmpClass.RandomCode = “222”;
tmpList.Add(tmpClass);
tmpList.OrderBy(p => p.MyID).ToList();
List<MyClass> tmpList = new List<MyClass>();
tmpClass.MyID = “5”;
tmpClass.RandomCode = “555”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “3”;
tmpClass.RandomCode = “333”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “1”;
tmpClass.RandomCode = “111”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “4”;
tmpClass.RandomCode = “444”;
tmpList.Add(tmpClass);
tmpClass = new MyClass();
tmpClass.MyID = “2”;
tmpClass.RandomCode = “222”;
tmpList.Add(tmpClass);
tmpList.OrderBy(p => p.MyID).ToList();
查看结果,排序还是 5 3 1 4 2 ?
本人想把里面的 排序成 12345 问一下不能排序是什么原因
解决方案
15
tmpList = tmpList.OrderBy(p => p.MyID).ToList();
15
或tmpList.Sort((x,y)=>{ return x.MyID.CompareTo(y.MyID); });