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.
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();
}
}
}
Comments
Leave a comment