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