精品收藏---集合之Array.Reverse 方法的技巧
来源:互联网 发布:网件路由器访客网络 编辑:程序博客网 时间:2024/05/22 01:55
语法
public static void Reverse(
Array array
)
Array array
)
参数
- array
- 类型:System.Array
要反转的一维 Array。
示例
下面的代码示例说明如何反转 Array 中的值的排序。
using System;public class SamplesArray { public static void Main() { // Creates and initializes a new Array. Array myArray=Array.CreateInstance( typeof(String), 9 ); myArray.SetValue( "The", 0 ); myArray.SetValue( "quick", 1 ); myArray.SetValue( "brown", 2 ); myArray.SetValue( "fox", 3 ); myArray.SetValue( "jumps", 4 ); myArray.SetValue( "over", 5 ); myArray.SetValue( "the", 6 ); myArray.SetValue( "lazy", 7 ); myArray.SetValue( "dog", 8 ); // Displays the values of the Array. Console.WriteLine( "The Array initially contains the following values:" ); PrintIndexAndValues( myArray ); // Reverses the sort of the values of the Array. Array.Reverse( myArray ); // Displays the values of the Array. Console.WriteLine( "After reversing:" ); PrintIndexAndValues( myArray ); } public static void PrintIndexAndValues( Array myArray ) { for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ ) Console.WriteLine( "\t[{0}]:\t{1}", i, myArray.GetValue( i ) ); }}/* This code produces the following output.The Array initially contains the following values: [0]: The [1]: quick [2]: brown [3]: fox [4]: jumps [5]: over [6]: the [7]: lazy [8]: dogAfter reversing: [0]: dog [1]: lazy [2]: the [3]: over [4]: jumps [5]: fox [6]: brown [7]: quick [8]: The*/
语法
public static void Reverse(
Array array,
int index,
int length
)
Array array,
int index,
int length
)
参数
- array
- 类型:System.Array
要反转的一维Array。
- index
- 类型:System.Int32
要反转的部分的起始索引。
- length
- 类型:System.Int32
要反转的部分中的元素数。
下面的代码示例显示如何反转 Array 中某部分元素的值序。
using System;public class SamplesArray { public static void Main() { // Creates and initializes a new Array. Array myArray=Array.CreateInstance( typeof(String), 9 ); myArray.SetValue( "The", 0 ); myArray.SetValue( "QUICK", 1 ); myArray.SetValue( "BROWN", 2 ); myArray.SetValue( "FOX", 3 ); myArray.SetValue( "jumps", 4 ); myArray.SetValue( "over", 5 ); myArray.SetValue( "the", 6 ); myArray.SetValue( "lazy", 7 ); myArray.SetValue( "dog", 8 ); // Displays the values of the Array. Console.WriteLine( "The Array initially contains the following values:" ); PrintIndexAndValues( myArray ); // Reverses the sort of the values of the Array. Array.Reverse( myArray, 1, 3 ); // Displays the values of the Array. Console.WriteLine( "After reversing:" ); PrintIndexAndValues( myArray ); } public static void PrintIndexAndValues( Array myArray ) { for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ ) Console.WriteLine( "\t[{0}]:\t{1}", i, myArray.GetValue( i ) ); }}/* This code produces the following output.The Array initially contains the following values: [0]: The [1]: QUICK [2]: BROWN [3]: FOX [4]: jumps [5]: over [6]: the [7]: lazy [8]: dogAfter reversing: [0]: The [1]: FOX [2]: BROWN [3]: QUICK [4]: jumps [5]: over [6]: the [7]: lazy [8]: dog*/
- 精品收藏---集合之Array.Reverse 方法的技巧
- johnsuna 的收藏精品
- 我的收藏精品
- Array.Reverse 方法
- 我的长期收藏精品
- [ios开发技巧之]UINavigationbar的背景修改方法集合
- Java基础之集合框架--Collections.reverse()方法
- 收藏一些精品的Java电子书
- 精品收藏--GUID强大的算法
- Eclipse使用技巧及快捷键大全(精品集合)
- Eclipse使用技巧及快捷键大全(精品集合)
- Eclipse使用技巧及快捷键大全(精品集合)
- 收藏的一个关于C# ToString的方法集合
- 精品网址收藏
- 精品代码收藏
- 400精品文章收藏
- 精品代码收藏
- SQL语句精品收藏
- Javascript实现单链表简单操作
- html5中的header元素在ie8里面的样式重构注意的地方
- debian下完全卸载openoffice
- jdbc.properties 包含多种数据库驱动链接
- 如何正确计算LINUX内存使用率
- 精品收藏---集合之Array.Reverse 方法的技巧
- Oracle专用服务器与共享服务器的区别
- Linux应用软件安装基本方法
- Frambuffer + SDL
- SAP财务管理相关概念
- Oracle数据库中的“专用服务器模式”与“共享服务器模式”
- 微软的战略想法~Microsoft Xbox Next Details。。。
- ORA-01552 非系统表空间不能使用系统回滚段处理
- 在分页中控制由用户输入页码来跳转的JS函数