how to sort string without using sort method

Posted by Vibheesh under C# on 12/6/2011 | Points: 10 | Views : 1692 | Status : [Member] | Replies : 1
i want to sort a string compare using ascii characters.
please write a program for me




Responses

Posted by: Hmanjarawala on: 12/7/2011 [Member] Bronze | Points: 25

Up
0
Down
static void Main(string[] args)
{
string[] strOceans = new string[] { "Pacific", "Arkatic", "Atlantic", "Indian", "Antartic" };

for (int i = 0; i < strOceans.Length; i++)
{
for (int j = i; j < strOceans.Length; j++)
{
if (string.Compare(strOceans[i], 0, strOceans[j], 0, ((strOceans[i].Length > strOceans[j].Length) ? strOceans[j].Length : strOceans[i].Length), StringComparison.CurrentCulture) > 0)
{
string temp = strOceans[i];
strOceans[i] = strOceans[j];
strOceans[j] = temp;
}
}
}

MessageBox.Show(string.Join(",", strOceans));
}

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Vibheesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response