class Host
{
public int[] a = {2,4,5,9,5,3,8,1 };
public void Sorting()
{
Array.Sort(a);//升序排列的方法
Array.Reverse(a);//把数组元素反向输出
}
}
主函数中这样写
Host ho = new Host();
ho.Sorting();
for (int i = 0; i < ho.a.Length; i++)
{
Debug.Log(ho.a[i]);
}
本文介绍了一个简单的C#程序示例,展示了如何使用内置的Array类方法对数组进行排序和反转。通过实例代码,读者可以了解到如何创建一个包含排序和反转功能的方法,并在主函数中调用该方法来展示排序后的数组。
1441

被折叠的 条评论
为什么被折叠?



