Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BRACKEYS - Solution to C# Tutorial 05 Challenge

13»

Comments

  • using System;


    namespace My_awesome_program

    {

      class Program

      {

        static void Main(string[] args)

        {

          Console.WriteLine("How many students do you have?");

          int nrStud = Int32.Parse(Console.ReadLine());

          string[] students = new string[nrStud];


          Console.WriteLine($"Okey, so {nrStud} students, please write their names, and ill display in alphabetical order");


          for (int i = 0; i < students.Length; i++)

          {

            students[i] = Console.ReadLine();

          }

          Console.WriteLine("--------------------------");

          Console.WriteLine("Here they are in alphabetical order");

          //Sorting in alhpabetical order

          Array.Sort(students);

          for (int i = 0; i < students.Length; i++)

          {

            Console.WriteLine(students[i]);

          }

           

          //Close program

          Console.ReadKey();

        }

      }

    }

  • That's my solution!

  • The program did work well , but there was just one error that would not go away at line 20

    using System;
    
    
    namespace MyApp // Note: actual namespace depends on the project name.
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "Students";
    
    
                Console.Write("How many students are there in your class? ");
                int numStudents = Convert.ToInt32(Console.ReadLine());
    
    
                string[] students = new string[numStudents];
    
    
                Console.WriteLine("Enter the names of the students: ");
    
    
                for (int i = 0; i < students.Length; i++)
                {
                    students[i] = Console.ReadLine();
                }
    
    
                Console.WriteLine("\nHere they are alphabetically: ");
    
    
                Array.Sort(students);
                for (int i = 0; i < students.Length; i++)
                {
                    Console.WriteLine(students[i]);
                }
    
    
                Console.ReadKey();
            }
        }
    }
    
Sign In or Register to comment.