Array数组的使用方法,包括Sort(),Reverse(),Copy()等
2011-11-23 09:50
633 查看
这个方法可以实现对数组中元素的排序(默认是升序排列的)
输出结果:
5→4→3→2→1→
1→2→3→4→5→
同样,Array.Reverse()就是把数组的所有元素都反转过来
eg. 如果原先是1,14,5,9,78,
Reverse之后就是78,9,5,14,1
Array.Copy举个例子就能说明
eg. int [] myArray={1,2,3,4,5}
newArr=new int[3] //定义一个长度为3的数组
Array.Copy(myArray,newArr,3)//意为将原有数数组myArray数组中的3个元素复制到数组newArr中,那么newArr的元素就是{1,2,3}
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] array = { 5,4,3,2,1}; for (int i = 0; i < array.Length; i++) { Console.Write(array[i]+"→"); } Console.WriteLine(); Array.Sort(array); for (int j = 0; j < array.Length; j++) { Console.Write(array[j] + "→"); } Console.ReadKey(); } } }
输出结果:
5→4→3→2→1→
1→2→3→4→5→
同样,Array.Reverse()就是把数组的所有元素都反转过来
eg. 如果原先是1,14,5,9,78,
Reverse之后就是78,9,5,14,1
Array.Copy举个例子就能说明
eg. int [] myArray={1,2,3,4,5}
newArr=new int[3] //定义一个长度为3的数组
Array.Copy(myArray,newArr,3)//意为将原有数数组myArray数组中的3个元素复制到数组newArr中,那么newArr的元素就是{1,2,3}
相关文章推荐
- js使用Array.prototype.sort()对数组对象排序的方法
- 浅谈JavaScript--Array数组sort()排序方法与自定义比较器的使用
- js数组排序 reverse()和sort()方法的使用 复制数组slice()和克隆数组concat()
- js使用Array.prototype.sort()对数组对象排序的方法
- js数组Array sort方法使用深入分析
- 使用Array的Sort()方法对数组进行排序
- js中的数组Array定义与sort方法使用示例
- js中的数组Array定义与sort方法使用示例
- js中的数组Array定义与sort方法使用示例
- javascript数组(array)的常用方法(shift/unshift/pop/push/concat/splice/reverse/sort/slice/join)
- 定义Car类,包含两个字段:name和price; (2)在Main方法中,使用Array.Sort方法对Car对象数组根据姓名和价格排序。
- js数组排序 reverse()和sort()方法的使用,
- java中Collections常用方法总结(包括sort,copy,reverse等)
- 数组与集合的应用之数组排序与查询(使用Sort方法对数组进行排序)
- JAVA-System.arraycopy方法的使用
- Python之数组(array)使用方法总结与Numpy中的数组用法
- JAVA System.arraycopy方法的使用
- 5个数组Array方法: indexOf、filter、forEach、map、reduce使用实例
- 数组排序方法的性能比较(中):Array.Sort 实现分析
- 使用System.arraycopy()实现数组之间的复制