C# List Reverse(Int32, Int32)
Description
List
reverses the order
of the elements in the specified range.
Syntax
public void Reverse(
int index,
int count
)
Parameters
index
- The zero-based starting index of the range to reverse.count
- The number of elements in the range to reverse.
Example
The following example demonstrates both overloads of the Reverse method.
//from w ww.ja v a 2s .c o m
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<string> myData = new List<string>();
myData.Add("C");
myData.Add("B");
myData.Add("newValue");
foreach(string myD in myData)
{
Console.WriteLine(myD);
}
myData.Reverse();
Console.WriteLine();
foreach(string myD in myData)
{
Console.WriteLine(myD);
}
myData.Reverse(1, 4);
Console.WriteLine();
foreach(string myD in myData)
{
Console.WriteLine(myD);
}
}
}
The code above generates the following result.