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 请问不能排序是什么原因
5 个解决方案
#1
tmpList = tmpList.OrderBy(p => p.MyID).ToList();
#2
原来.....我以为跟 .add 一样直接执行了
谢谢你
#3
或tmpList.Sort((x,y)=>{ return x.MyID.CompareTo(y.MyID); });
#4
谢谢你的教学 ^^
#5
#1
tmpList = tmpList.OrderBy(p => p.MyID).ToList();
#2
tmpList = tmpList.OrderBy(p => p.MyID).ToList();
原来.....我以为跟 .add 一样直接执行了
谢谢你
#3
tmpList = tmpList.OrderBy(p => p.MyID).ToList();
或tmpList.Sort((x,y)=>{ return x.MyID.CompareTo(y.MyID); });
#4
tmpList = tmpList.OrderBy(p => p.MyID).ToList();
或tmpList.Sort((x,y)=>{ return x.MyID.CompareTo(y.MyID); });
谢谢你的教学 ^^