|zyciis| ArrayList.Reverse();的具体功能是什么,具体怎么个用法,有谁帮贴一个中文的说明

zyciis324 2009-05-01 12:36:53
如题
谢谢
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
云想慕尘 2009-05-01
  • 打赏
  • 举报
回复
云想慕尘 2009-05-01
  • 打赏
  • 举报
回复
此方法使用 Array.Reverse 将元素的顺序反转,从而使得 ArrayList [i](其中 i 表示该范围内的任何索引)处的元素移到 ArrayList [j](其中 j 等于 index + index + count - i - 1)。
using System;
using System.Collections;
public class SamplesArrayList {

public static void Main() {

// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add( "The" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );
myAL.Add( "jumps" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );

// Displays the values of the ArrayList.
Console.WriteLine( "The ArrayList initially contains the following values:" );
PrintValues( myAL );

// Reverses the sort order of the values of the ArrayList.
myAL.Reverse();

// Displays the values of the ArrayList.
Console.WriteLine( "After reversing:" );
PrintValues( myAL );
}

public static void PrintValues( IEnumerable myList ) {
foreach ( Object obj in myList )
Console.WriteLine( " {0}", obj );
Console.WriteLine();
}

}


/*
This code produces the following output.

The ArrayList initially contains the following values:
The
quick
brown
fox
jumps
over
the
lazy
dog

After reversing:
dog
lazy
the
over
jumps
fox
brown
quick
The
*/

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧