Answer to Question #255597 in C# for vusamazulu

Question #255597

Write a program that allows the user to enter any number of names; i.e – last name and first name. Using one of the predefined methods of the Array class, order the names in ascending order. Display the results.


1
Expert's answer
2021-10-23T23:31:20-0400
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter number of names: ");
            var names_number = int.Parse(Console.ReadLine());
            var names = new String[names_number];

            for (var i = 0; i < names_number; i++)
            {
                Console.Write("Enter name: ");
                names[i] = Console.ReadLine();
            }

            Array.Sort(names);
            foreach (var name in names)
            {
                Console.WriteLine(name);
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS