如何在C#中按升序排列数组元素? [英] How to arrange the array elements in ascending order in C#?

查看:94
本文介绍了如何在C#中按升序排列数组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助解决这种情况:

有一个项目需要接受用户的数组元素和值的总数。它还需要按升序排列数组元素,并显示结果。 (提示:数组应该是一个整数数组)。如何在C#中编写代码?



-Sun_Shine的问题.. :-D

Please help to solve this case:
There is a project that needs to accept the total number of array elements and values from the user. It also needs to arrange the array elements in ascending order, and display the result. (Hint: The array should be an integer array). How to write the code in C#?

-Question by Sun_Shine.. :-D

推荐答案

看看array.sort方法:

http://msdn.microsoft.com/en-us/library/aa311213%28VS.71%29.aspx [ ^ ]

或看到此链接有很多样本:

http://www.csharp-examples.net/sort-array/ [< a href =http://www.csharp-examples.net/sort-array/target =_ blanktitle =New Window> ^ ]
Have a look at the array.sort method:
http://msdn.microsoft.com/en-us/library/aa311213%28VS.71%29.aspx[^]
or see this link with a lot of samples:
http://www.csharp-examples.net/sort-array/[^]


添加到JF2015这也可能对你有所帮助。



Sortsandarrayinascendingorder [ ^ ]和 http://www.dotnetjohn.com/articles.aspx?articleid=181 [ ^ ]
Added to JF2015 this also might help you.

Sortsandarrayinascendingorder[^]and http://www.dotnetjohn.com/articles.aspx?articleid=181[^]


int[] array = new int[] { 3, 1, 4, 5, 2 };



//Declare Array



Array.Sort<int>( array );



// Sort Method used Asending Order



Array.Reverse( array );



// reverse Method used Decenting Order


这篇关于如何在C#中按升序排列数组元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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