Use the Item property explicitly to assign values to items in the list in CSharp
Description
The following code shows how to use the Item property explicitly to assign values to items in the list.
Example
using System;//from w w w . ja v a 2 s . c o m
using System.Collections;
public class ScrambleList : ArrayList
{
public static void Main()
{
ScrambleList integerList = new ScrambleList();
for (int i = 0; i < 10; i++)
{
integerList.Add(i);
}
foreach(object i in integerList){
Console.WriteLine(i);
}
integerList.Scramble();
foreach(object i in integerList){
Console.WriteLine(i);
}
}
public void Scramble()
{
int limit = this.Count;
int temp;
int swapindex;
Random rnd = new Random();
for (int i = 0; i < limit; i++)
{
temp = (int)this[i];
swapindex = rnd.Next(0, limit - 1);
this[i] = this[swapindex];
this[swapindex] = temp;
}
}
}
The code above generates the following result.