一维数组的声明和使用

闲的无聊记录点知识:

1.声明

type[] arrayName;

type表示数据类型

arrayName表示数组名称

例:int[] arr;

2.初始化

int[] arr=new int[5];//次数组长度为五

int[] arr=new int[5]{1,2,3,4,5};//赋值

直接对数组进行初始化

string[] arrStr={"sum","mon","wed","htu","sat"};

Array类的Sort和Reverse排序方法

sort对数组进行从小到大的的排序,(注:此方法只能对一维数组,而且这个一维数组不能为空)

int[] arr=new int[]{1,4,34,5,87,6,65};

Array.Sort(arr);

Reverse对数组进行反转

Array.Reverse(arr);

原文地址:https://www.cnblogs.com/yangxinghua/p/3658461.html