How to Elements of Array in descending order?

No.of Views2227
Bookmarked0
By RRaveen  On 22 Dec 2010
emailbookmarkadd commentsprint
 

Answer:

1.Call Sort() method for Array Then

2.Reverse() Method for Array.

Sample Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] sample = new string[] { "RRaveen", "John", "Murukan", "Dhan" };            
            Array.Sort(sample);
            Array.Reverse(sample);

            for (int i = 0; i < sample.Length; i++)
            {
                Console.WriteLine(sample[i]);
                
            }
            Console.ReadLine();
         }
     }
}

Output

RRaveen
Murukan
John
Dhan
 
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popular Interview Questions On CSharp
^ Scroll to Top