Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

How to: Sort Arrays

Unlike standard C++ arrays, managed arrays are implicitly derived from an array base-class from which they inherit common behaviors. A prime example is the Sort method, which can be used to order the items in any array.

For arrays containing simple intrinsic types, you can call the Sort method. The sort criteria can be overridden, which is necessary to sort for arrays of complex types. In this case, the array element type must implement the IComparable::CompareTo method.


using namespace System;

int main() {
   array<int>^ a = { 5, 4, 1, 3, 2 };
   Array::Sort( a );
   for (int i=0; i < a->Length; i++)
      Console::Write("{0} ", a[i] );

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.