Ads by Lake Quincy Media
| Next Tip?
Home » CSharp

Sorting an array in c#

26 June 2009 611 views 4 Comments
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading ... Loading ...

using System;
class SortReverse
{
public static void Main()
{
int[] x={30,10,80,90,20};
Console.WriteLine(“Array Before Sorting”);
foreach(int i in x)
Console.Write(” “+i);
Console.WriteLine();
Array.Sort(x);
Console.WriteLine(“Array After Sorting”);
foreach(int i in x)
Console.Write(” “+i);
Console.WriteLine();
Array.Reverse(x);
Console.WriteLine(“Array After Reversing”);
foreach(int i in x)
Console.Write(” “+i);
Console.WriteLine();
}
}

Hi,

Here is a simple way to sort an array. We can use the Array.Sort() function for applying the sorting. Here I am going to display a short code snippet for your use. Try and and post your comments here. If any suggestions or need some clarifications
using System;

class SortReverse

{

public static void Main()

{

int[] x={30,10,80,90,20};

Console.WriteLine("Array Before Sorting");

foreach(int i in x)

Console.Write(" "+i);

Console.WriteLine();


Array.Sort(x);

Console.WriteLine("Array After Sorting");

foreach(int i in x)

Console.Write(" "+i);

Console.WriteLine();


Array.Reverse(x);


Console.WriteLine("Array After Reversing");

foreach(int i in x)

Console.Write(" "+i);

Console.WriteLine();


}

}


Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Popularity: 10%

Post to Twitter Tweet This Post

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Ads by Lake Quincy Media

4 Comments »

  • Gaurav Arora said:

    Hi Anil,

    Good work. Its a nice code presented by you.
    Welcome to MsDnM.

    Keep it up!

    Best of luck!

    Gaurav Arora

  • ANIL PANDEY (author) said:

    Thanks for your valuable comment, i will keep posting codes like this..

  • Lacy said:

    Cool post, just subscribed.

  • ANIL PANDEY (author) said:

    Thanks for your appreciation….

Leave your response!

You must be logged in to post a comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes