日期:2014-05-17  浏览次数:20397 次

.net中对集合类型数据orderby()问题
比如有这么一个集合对象,对它进行排序:List.OrderBy(p => p.Sort)。
集合中有三条数据,sort分别是1、2、10.orderby后顺序就变成了1,10,2。顺序错了 顺序应该是1,2,10。从小到达排列。不知道怎么解决?
.net linq?lamuda

------解决方案--------------------
Sort转为int型
------解决方案--------------------
转成int再排,或者多加一个字符长度
------解决方案--------------------
List.OrderBy(p => int.Parse(p.Sort))
或者
List.OrderBy(p => p.Length).ThenBy(p => p.Sort)
------解决方案--------------------
orderby int.Parse(p.Sort)
------解决方案--------------------
引用:
orderby int.Parse(p.Sort)

linq
------解决方案--------------------
引用:
比如有这么一个集合对象,对它进行排序:List.OrderBy(p => p.Sort)。
集合中有三条数据,sort分别是1、2、10.orderby后顺序就变成了1,10,2。顺序错了 顺序应该是1,2,10。从小到达排列。不知道怎么解决?
              
                  .net
                  linq la……

说明List中元素不是整形的,是字符串

转换一下
List.OrderBy(p => Int.Parse(p.Sort))