March 2004
Intermediate to advanced
560 pages
26h 47m
English
using System;
using System.Collections;
namespace Samples
{
public class ArraySample
{
public class MyReverseComparer: IComparer
{
public int Compare(Object a, Object b)
{
return -((IComparable)a).CompareTo(b);
}
}
public static void Main()
{
string[] strings = {"one", "two", "three"};
Console.WriteLine("Array elements: ");
Display(strings);
Array.Reverse(strings);
Display(strings);
Array.Sort(strings);
Display(strings);
Array.Sort(strings, new MyReverseComparer());
Display(strings);
}
public static void Display(Array a)
{
foreach(object o in a)
Console.Write("{0} ", o);
Console.WriteLine();
}
}
}
Array elements: one two three three two one one three two two three one
Read now
Unlock full access