asp.net.ph

Array.Sort Method ( Array, Int32, Int32, IComparer )

System Namespace   Array Class


Sorts the elements in a section of a one-dimensional Array using the specified IComparer interface.

[ VB ]
<Serializable>
Overloads Public 
Shared Sub Sort ( _
   ByVal array As Array, _
   ByVal index As Integer, _
   ByVal length As Integer, _
   ByVal comparer As IComparer _
)

[ C# ]
[Serializable]
public static void Sort (
   Array array,
   int index,
   int length,
   IComparer comparer
);

[ C++ ]
[Serializable]
public: static void Sort (
   Array* array,
   int index,
   int length,
   IComparer* comparer
);

[JScript ]
public Serializable
static function Sort (
   array : Array,
   index : int,
   length : int,
   comparer : IComparer
);

Parameters

array
The one-dimensional Array to sort.
index
The starting index of the range to sort.
length
The number of elements in the range to sort.
comparer
The IComparer implementation to use when comparing elements.

-or-

A null reference ( Nothing in Visual Basic ) to use the IComparable implementation of each element.

Exceptions


Exception Type Condition
ArgumentNullException array is a null reference ( Nothing in Visual Basic ).
RankException array is multidimensional.
ArgumentOutOfRangeException index is less than the lower bound of array.

-or-

length is less than zero.

ArgumentException index and length do not specify a valid range in array.
InvalidCastException comparer is a null reference ( Nothing in Visual Basic ) , and one or more elements in array do not implement the IComparable interface.
InvalidOperationException The comparer throws an exception.

Remarks

If comparer is a null reference ( Nothing in Visual Basic ) , each element within the specified section of array must implement the IComparable interface to be capable of comparisons with every other element in array.

If the sort is not successfully completed, the results are undefined.

This method uses the QuickSort algorithm. This is an O ( n log2n ) operation, where n is the number of elements to sort.

See Also

Array Members   Array.Sort Overload List   IComparer   IComparable   BinarySearch Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph