排序列表< INT> [英] Sorting a List<int>

查看:156
本文介绍了排序列表< INT>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#什么是数字排序列表的最好方法?
我的列表中有项5,7,3,我想他们整理3,5,7。我知道一些较长的方式,但我想LINQ有一个更快的方法?



对不起,这是一天结束时,我的心是别的地方,它的工作,没有看到它改变了第一次:(


解决方案

有没有需要LINQ在这里,只需拨打排序:

  list.Sort(); 

示例代码:



<为pre> 列表< INT>列表=新的List< INT> {5,7,3};
list.Sort();
的foreach(INT中X名单)
{
Console.WriteLine(X);
}

结果:

  3 
5
7


Using C# what is the best way to sort a List numerically? my list has items 5,7,3 and I would like them sorted 3,5,7. I know some longer ways, but I would imagine linq has a quicker way?

sorry this was end of day, my mind is else where it worked, didn't see it change the first time:(

解决方案

There's no need for LINQ here, just call Sort:

list.Sort();

Example code:

List<int> list = new List<int> { 5, 7, 3 };
list.Sort();
foreach (int x in list)
{
    Console.WriteLine(x);
}

Result:

3
5
7

这篇关于排序列表&LT; INT&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆