Forums - C# Corner

Forum guidelines
Pavi S

Pavi S

  • 733
  • 29
  • 41.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)

Startup Conference 2016

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.