Forums - C# Corner

Forum guidelines
Pavi S

Pavi S

  • 1.3k
  • 41
  • 43.6k

Bubble sort using string array in C#

Jan 26 2012 11:32 PM
please help  me to sort the string array in bubble sort method.

Please help me sort [without using Collectons or Array.Sort()] the string array in the following code snippet:


using System;

class MainClass
{
    static void Main()
    {  
        string[] s = {"Bill", "Gates", "James", "Apple", "Net", "Java"};

        try
        {
            for(int i=0; i            {
                for(int j=0; j                {
                    for(int k=0; k                        if(s[j][k] > s[j+1][k])
                        {
                            string temp = s[j];
                            s[j] = s[j+1];
                            s[j+1] = temp;
                        }

                }
            }             
        }

        catch(Exception)
        {

        } 

        for(int i=0; i        {
            Console.WriteLine(sIdea + " ");
        }               
    }
}




the above code throwing error please help me to sort string array.


Answers (3)

Unlimited Flat-Free License

SPONSORED BY

File APIs for .NET
Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!