i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sort the elements of the array in descending order
09-23-2010, 10:50 AM
Post: #1
Sort the elements of the array in descending order
Code:
Using Array.Sort() and Array.Reverse() methods to sort array in descending order.

Example:

int[] arr = new int[3];
arr[0] = 4;
arr[1] = 1;
arr[2] = 5;

//sorting array arr[]
Array.Sort(arr);

//Reversing array arr[]
Array.Reverse(arr);




Thanks Regards
Shafiur Rahman
http://www.createsoftweb.com
Quote
10-02-2010, 01:53 AM
Post: #2
RE: Sort the elements of the array in descending order
good post. keep contributing.


Thanks and Regards
Raju
Quote
10-02-2010, 10:02 AM
Post: #3
RE: Sort the elements of the array in descending order
Hi,
Will it work with string arrays as well??

Oracle Certified Trainer
[Image: signature.php?uid=40]
Quote
10-03-2010, 04:36 PM (This post was last modified: 10-04-2010 05:08 AM by nisar87.)
Post: #4
RE: Sort the elements of the array in descending order
yes! it will also work with string array
like
Code:
string[] arr = new string[3];
        arr[0] = "abc";
        arr[1] = "def";
        arr[2] = "ghi";

        //sorting array arr[]
        Array.Sort(arr);

        //Reversing array arr[]
        Array.Reverse(arr);

the result will be
Code:
ghi
def
abc

[Image: 2604595733.png]
Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Order number of datagridview ? dongtrien 0 790 11-30-2015 06:40 AM
Last Post: dongtrien
  Convert String Array to Int Array nisar87 0 1,832 10-03-2012 07:49 AM
Last Post: nisar87
  List descending order using Linq C# nisar87 2 8,105 08-02-2012 08:25 AM
Last Post: haider.ali
Wink Sorting of array sankkrit 0 1,155 12-27-2011 09:23 AM
Last Post: sankkrit
  XAML Properties as Elements arti.porwal20@gmail.com 0 1,339 10-28-2010 04:10 AM
Last Post: arti.porwal20@gmail.com



User(s) browsing this thread: 1 Guest(s)