Ask Your Question
4

How can a console-app sort a list in alphabetical order?

asked 2021-05-30 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-01-07 09:00:00 +0000

david gravatar image

Here is an example code in C# that sorts a list of strings in alphabetical order:

using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<string> names = new List<string>() {"John", "Alice", "Bob", "Mary"};

        names.Sort();

        foreach (string name in names)
        {
            Console.WriteLine(name);
        }
    }
}

The List<T>.Sort method is used to sort the list of strings in-place. The foreach loop is used to print the sorted list.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-30 11:00:00 +0000

Seen: 1 times

Last updated: Jan 07 '23