none
Sorting Arrays Alphabetically. RRS feed

Answers

  • This worked for me:

            string[] names = { "a", "x", "c", "e" };
            var sortedNames = names.OrderBy(n => n);
            foreach (var item in sortedNames)
            {
              Console.WriteLine(item);
            }
    
    

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Marked as answer by C SHARP DENNY Tuesday, September 14, 2010 6:27 AM
    Sunday, September 12, 2010 4:09 AM
  • Array.Sort(names);
    • Marked as answer by C SHARP DENNY Tuesday, September 14, 2010 6:27 AM
    Sunday, September 12, 2010 4:25 AM
  • Hi,

    Using Array.Sort would be more efficient.

    string[] names = { "a", "x", "c", "e" };
    Array.Sort(names);	
    

    Best,

    Nyi Nyi

     


    Happy programming .net
    • Marked as answer by C SHARP DENNY Tuesday, September 14, 2010 6:27 AM
    Sunday, September 12, 2010 4:28 AM

All replies

  • This worked for me:

            string[] names = { "a", "x", "c", "e" };
            var sortedNames = names.OrderBy(n => n);
            foreach (var item in sortedNames)
            {
              Console.WriteLine(item);
            }
    
    

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Marked as answer by C SHARP DENNY Tuesday, September 14, 2010 6:27 AM
    Sunday, September 12, 2010 4:09 AM
  • Array.Sort(names);
    • Marked as answer by C SHARP DENNY Tuesday, September 14, 2010 6:27 AM
    Sunday, September 12, 2010 4:25 AM
  • Hi,

    Using Array.Sort would be more efficient.

    string[] names = { "a", "x", "c", "e" };
    Array.Sort(names);	
    

    Best,

    Nyi Nyi

     


    Happy programming .net
    • Marked as answer by C SHARP DENNY Tuesday, September 14, 2010 6:27 AM
    Sunday, September 12, 2010 4:28 AM
  • Thanks very much. Here is the code I wound up using:

    using System;

    public class Assignment_19 {

    public static void Main(string[]args) {

    string[] names = new string[10];


    names[0] = "Dennis";
    names[1] = "John";
    names[2] = "Fred";
    names[3] = "Martin";
    names[4] = "Ron";
    names[5] = "Wally";
    names[6] = "Angelo";
    names[7] = "Sharon";
    names[8] = "Jessie";
    names[9] = "Kelsey";

    Array.Sort(names);

    for(int row = 0; row<names.Length; row++)
    Console.WriteLine(names[row]);

         }
       }

    Tuesday, September 14, 2010 6:31 AM