您的位置:首页 > 编程语言 > C#

C#中的数组中的方法(一个例子)

2007-04-18 16:57 218 查看
在C#中的数组对象,可以用Reverse()方法颠倒数组中的元素顺序。Reverse()方法是一个静态方法,所以作为参数将需要颠倒顺序的数组元素传递给Reverse()方法。

Array.Reverse(Interger);

使用Sort()方法可以对数组的元素进行排序。

Array.Sort(Integer);

考虑一个例子,数组中存储了学生分数,需要对数据进行排序,以确定最高分和最低分。

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] Marks = {70, 75, 84, 53, 46, 90, 25 };
int I = Marks.Length;

Console.Write("初始排序为:70, 75, 84, 53, 46, 90, 25");
System.Threading.Thread.Sleep(2000);

Array.Sort(Marks);
Console.WriteLine("");
Console.WriteLine("按照从小到大的顺序排序后为:");
System.Threading.Thread.Sleep(2000);

for (int x = 0; x < I; x++)
{
Console.WriteLine(Marks[x]);
System.Threading.Thread.Sleep(1000);
}
Console.Read();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐