一维/二维数组:
int[] myintArray = { 1, 2, 3 ,9,15,32,4};
int[,] myintArray= { { 12, 34 }, { 56, 78 } };
数据升序/降序:
int[] myintArray = { 1, 2, 3 ,9,15,32,4};
Array.Sort(myintArray);
foreach(int outint in myintArray)
System.Diagnostics.Debug.WriteLine("升序"+"\r"+outint + "\r");
Array.Reverse(myintArray);
foreach (int outint in myintArray)
System.Diagnostics.Debug.Write("降序" + "\r" + outint + "\r");
数组的合并:
int[] myintArray = { 1, 2, 3 ,9,15,32,4};
int[] myintArray2 = { 11, 22, 33, 99, 155, 322, 44 };
foreach (int outint in myintArray)
System.Diagnostics.Debug.WriteLine("原数组1为:" + outint + "\r");
foreach (int outint in myintArray2)
System.Diagnostics.Debug.WriteLine("原数组2为:" + outint+ "\r");
int[] resultNum = new int[20];
int mA_longth = myintArray.GetLength(0);//数组1长度
int mA2_longth = myintArray2.GetLength(0);//数组2长度
Array.Copy(myintArray, resultNum, mA_longth);
Array.Copy(myintArray2, 0, resultNum, mA_longth, mA2_longth);
foreach (int outint in resultNum)
System.Diagnostics.Debug.WriteLine("使用第一种:" + outint + "\r");
ArrayList添加和删除数组内容:
//数组添加
ArrayList myArrayList = new ArrayList(5);
myArrayList.Add(1);
myArrayList.Add(2);
myArrayList.Add(3);
myArrayList.Add("A");
myArrayList.Add("B");
myArrayList.Add("C");
System.Diagnostics.Debug.WriteLine("数组数量为{0}" , myArrayList.Count );
string[] mystringArray = { "张三","李四","王五"};
myArrayList.AddRange(mystringArray);
System.Diagnostics.Debug.WriteLine("range数组数量为{0}" ,myArrayList.Count);
foreach (object outarray in myArrayList)
System.Diagnostics.Debug.WriteLine("数组元素"+outarray+"\r");
//数组删除
myArrayList.Remove("A");
foreach (object outarray in myArrayList)
System.Diagnostics.Debug.WriteLine("删除后" + outarray + "\r");
myArrayList.RemoveAt(4);
foreach (object outarray in myArrayList)
System.Diagnostics.Debug.WriteLine("删除索引后" + outarray + "\r");
myArrayList.RemoveRange(4, 3);
foreach (object outarray in myArrayList)
System.Diagnostics.Debug.WriteLine("删除区间索引后" + outarray + "\r");
myArrayList.Clear();
foreach (object outarray in myArrayList)
System.Diagnostics.Debug.WriteLine("删除所有元素后" + outarray + "\r");
ArrayList数组查询:
//数组添加
ArrayList myArrayList = new ArrayList(5);
myArrayList.Add(1);
myArrayList.Add(2);
myArrayList.Add(3);
myArrayList.Add("A");
myArrayList.Add("B");
myArrayList.Add("C");
//查找数据
int indexResult= myArrayList.IndexOf("张三");
foreach (object outarray in myArrayList)
System.Diagnostics.Debug.WriteLine("查询结果{0}" ,indexResult );
int indexResult_La = myArrayList.LastIndexOf("王五");
foreach (object outarray in myArrayList)
System.Diagnostics.Debug.WriteLine("查询结果{0}", indexResult_La);
//int indexResult_LaB = myArrayList.BinarySearch("王五");//首次出现索引值
//foreach (object outarray in myArrayList)
// System.Diagnostics.Debug.WriteLine("查询结果{0}", indexResult_LaB);