Answer to Question #253036 in C# for Israel

Question #253036

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-21T02:20:45-0400
using System;
using System.Collections.Generic;


namespace App
{








    class Program
    {
        static void Main(string[] args)
        {


            int numberNames = -1;
            Console.Write("Enter the number of names: ");
            int.TryParse(Console.ReadLine(), out numberNames);
            string[] names = new string[numberNames];


            for (int i = 0; i < numberNames; i++)
            {
                Console.Write("Enter the last name: ");
                names[i] = Console.ReadLine();
            }


            Array.Sort(names);
            Console.WriteLine("Sorted names: ");
            for (int i = 0; i < numberNames; i++)
            {
                Console.WriteLine(names[i]);


            }


            Console.ReadLine();
        }


    }
}

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
New on Blog
APPROVED BY CLIENTS