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

BrackeysBrackeys Administrator
edited August 12 in Announcements

Hey everyone!

Here is my solution to the challenge from the C# Tutorial 05 (Arrays) video that is out soon.

Have fun with it! 😀

using System;


namespace My_Awesome_Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("How many students are in your class: ");


            int studentCount = Convert.ToInt32(Console.ReadLine());


            Console.WriteLine("Please input the names of the students: ");


            string[] students = new string[studentCount];


            for (int i = 0; i < studentCount; i++)
            {
                students[i] = Console.ReadLine();
            }


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


            Array.Sort(students);


            for (int i = 0; i < studentCount; i++)
            {
                Console.WriteLine(students[i]);
            }


            // Wait before closing
            Console.ReadKey();
        }
    }
}


Comments

  • Here is mine.

    using System;
    
    
    namespace Awesome_Projects
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "FRIDAY";
    
    
                Console.Write("Number of students in class: ");
                int studentNumber = Convert.ToInt32(Console.ReadLine());
    
    
    
                string[] studentname = new string[studentNumber];                   //Creating Array
    
    
                Console.WriteLine("Enter the names:");
    
    
                for (int i = 0; i < studentname.Length; i++)                        //Array Input 
                {
                    studentname[i] = Console.ReadLine();
                }
    
    
                Console.WriteLine("\nThe names in alphabatical order:");  
                Array.Sort(studentname);                                            //Sorting
    
    
                for (int i = 0; i < studentname.Length; i++)                        //Array Output
                {
                    Console.WriteLine(studentname[i]);
                }           
                Console.ReadKey();                                                  // Wait before closing
            }
        }
    }
    
    
    
  • PraimusPraimus Member
    edited August 17

    Hey Here is Mine

    using System;
    
    
    namespace File
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "Praimus's Work";
              
                Console.Write("How many Students are there in your Class: ");
    
                int numOfStudents = Convert.ToInt32(Console.ReadLine());
                
                string[] studentName = new string[numOfStudents];
                Console.WriteLine("Write The Name of the Students");
                
                for (int i = 0; i < numOfStudents; i++)
                {
                    studentName[i] = Console.ReadLine();
                }
                Console.WriteLine("Wait let me sort it out\n");
                Array.Sort(studentName);
                
                for (int i = 0; i < numOfStudents; i++)
                {
                    int m = i + 1;
                    Console.WriteLine(m+": "+studentName[i]);
                }
            }
        }
    }
    


  • using System;

    using System.Collections.Generic;


    namespace Learning_C_

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title = "SouthMythKing";


                //Variables//

                int ammount;


                //Getting Them To Right How Many Students//

                Console.WriteLine("How Many Student Do u Have");

                Console.Write(":");

                ammount = Convert.ToInt32(Console.ReadLine());


                //Array//

                string[] studentNames = new string[ammount];


                //Getting The Student names//

                Console.WriteLine("What R There Names");

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

                {

                    studentNames[i] = Console.ReadLine();

                }


                //Putting Them In Alphabet Order//

                Array.Sort(studentNames);

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


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

                {

                    Console.WriteLine(studentNames[i]);

                }


                //Ending//

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

                Console.WriteLine("Thx For Using My Website");


                Console.ReadKey();

            }

        }

    }

  • ElkrazElkraz Member

    i managed to use list 😅

    using System;
    using System.Collections.Generic;
    
    
    namespace Arrays_or_List
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Write("Number of students to register: ");
                int number = Convert.ToInt32(Console.ReadLine());
    
    
                List<string> studentList = new List<string>();
                
                Console.WriteLine("Write names: ");
                for (int i = 0; i < number; i++)
                {
                    Console.Write(i+1 + ". ");
                    studentList.Add(Console.ReadLine());                
                }
                
                studentList.Sort();
                Console.WriteLine("\nSorting alphabetically...");
    
    
    
                for (int n = 0; n < studentList.Count; n++)
                {
                    Console.Write(n+1 + ". ");
                    Console.WriteLine(studentList[n]);                
                }
                
                Console.ReadKey();
                
            }
        }
    }
    
    
    
  • CodenNinjaCodenNinja Member
    edited August 17

    I have to fix some stuff on my code.

  • With Arrays

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    
    
    namespace CS_Practice
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Enter number of students: ");
                int no = Int32.Parse(Console.ReadLine());
                string[] students = new string[no];
    
    
    
    
                for (int i = 0; i < students.Length; i++)
                {
                    Console.WriteLine(i + 1 + ". Enter student name");
                    students[i] = Console.ReadLine();
                }
    
    
    
    
                Array.Sort(students);
                Console.WriteLine("\n---------------------");
                Console.WriteLine("Here are students sorted alphabetically:");
    
    
    
    
                for (int i = 0; i < students.Length; i++)
                {
                    Console.WriteLine(i + 1 + ". " + students[i]);
                }
    
    
    
    
                Console.WriteLine("Enter any key to exit");
                Console.ReadKey();
            }
        }
    }
    
    
    

    With Lists:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    
    
    namespace CS_Practice
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<string> students = new List<string>();
                while (true)
                {
                    Console.WriteLine("Enter student's name, write q to quit: ");
                    string name = Console.ReadLine();
                    if(name == "q")
                    {
                        break;
                    }
                    students.Add(name);
                }
    
    
                students.Sort();
    
    
                Console.WriteLine("\n----------------------");
                Console.WriteLine("Here are students names sorted alphabetically");
                for(int i=0; i<students.Count; i++)
                {
                    Console.WriteLine(i+1 + ". "+ students[i]);
                }
                Console.WriteLine("\n");
                Console.WriteLine("Press any key to quit");
                Console.ReadKey();
            }
        }
    }
    
    
    
  • using System;


    public class Array


    {


    static public void Main ()


        {


            Console.WriteLine("How many students are in your class");


    int num = Convert.ToInt32(Console.ReadLine());




    string[]students = newstring[num];




    for (int i = 0;i < num;i++)


       {


        students[i] = Console.ReadLine();


       }




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



    for (int i = 0;i < num;i++)


       {


    int rank = i + 1;


       Console.WriteLine(rank + "/ " + students[i]);


       }


       Console.ReadKey();


        }


    }

  • sorry7sorry7 Member

    using System;

    using System.Threading;

    using System.Windows.Forms;


    namespace Learning

    {

       class Program

       {

           static void Main(string[] args)

           {

               Write("How many students are there: ", ConsoleColor.White);

               try

               {

                   //int & array

                   int AmountOfStudents = int.Parse(Console.ReadLine());

                   string[] students = new string[AmountOfStudents];


                   //Question.. And i did not use write function because i use it when i need to color but as you can see just a few codes on top of it you'll see i already changed to the color i wanted so.....

                   Console.WriteLine("Enter there names here:");


                   // for loop...

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

                       students[i] = Console.ReadLine();


                   //Sorting the array in a alphabatic order

                   Array.Sort(students);

                   Console.WriteLine("------------------------------", ConsoleColor.White);

                   for (int i = 0; i < students.Length; i++) // To understand how a for loop works just watch part 3 or part 2 :)

                   {

                       int rank = i + 1; // Making a new int with 0 and then equals i witch is equals 0 + 1 and as the loop continues the 0 grows up and stops at the array length

                       Write($"{rank}: {students[i]}", ConsoleColor.Green); // You can use Write(rank + ": " + students[i]); but you should learn the way i did...

                   }

               }

               catch

               {

                   Console.Clear(); // Removing all past written text

                   Write("[ERROR] Please make sure you do not enter any letters ONLY numbers that whole not decimals", ConsoleColor.Red);

                   Thread.Sleep(TimeSpan.FromSeconds(4)); // Waiting 4 Secounds and does continues the code....

                   Application.Restart(); // Restarts the application....

               }



               Console.Read();

           }



           /*

              Not in the challenge but an cool extra thing to add

              Just makes color on the text and instead of typing a long console.writeline command its alot easier this way

           */

           private static void Write(string value, ConsoleColor color)

           {

               Console.ForegroundColor = color;

               Console.WriteLine(value);

           }

       }

    }

  • using System;

    using System.Collections.Generic;


    namespace Randal_the_Snitch

    {

        class Program

        {

            static void Main(string[] args)

            {

                 Console.WriteLine("Alright, so how many kids got the detention slip today?");


                 int studentCount = Convert.ToInt32(Console.ReadLine());


                 if (studentCount >= 20 ) {


                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("Wow, are kids today just born stupid?");

                    Console.ForegroundColor = ConsoleColor.Yellow;

                    Console.ReadKey();

                    Console.WriteLine("Whatever just give me the names:");

                    Console.ForegroundColor = ConsoleColor.White;

                 }

                

                else if (studentCount == 1) {

                    Console.ForegroundColor = ConsoleColor.Yellow;

                    Console.WriteLine("Wow really? The students here are never behaved!\n");

                    Console.ReadKey();

                    Console.ForegroundColor = ConsoleColor.White;

                    Console.WriteLine("Well whats the unlucky fellows name?");

                    

                }


                else {

                    Console.WriteLine("Alright Give me the names");

                }


                string[] students =  new string[studentCount];


                for (int i = 0; i < studentCount; i++)

                {

                    students[i] = Console.ReadLine();

                }


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


                Array.Sort(students);


                for (int i = 0; i < studentCount; i++)

                {

                    Console.WriteLine(students[i]);

                }


                Console.WriteLine("List Completed!");

                Console.ReadKey();

                

                if (studentCount >= 20 ) {


                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("\nHope those rotten kids enjoy their detention.");

                    Console.ForegroundColor = ConsoleColor.White;

                 }

                

                else if (studentCount == 1) {

                    Console.WriteLine("\nWell I hope they think about what they did.");

                    Console.ForegroundColor = ConsoleColor.White;

                }


                else {

                    Console.WriteLine("\nHope they learn a lesson");

                }


                // wait for input to close

                Console.ReadKey();

            }

        }

    }

  • [code]

    using System;

    namespace My_Awesome_Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                int studentCount = 0;

                Console.Write("How many students are in your class?: ");

                studentCount = Convert.ToInt32(Console.ReadLine());

                string[] names = new string[studentCount];

                Console.WriteLine("Please input the names of the students: ");

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

                {

                    names[i] = Console.ReadLine();

                }

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

                Array.Sort(names);

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

                {

                    Console.WriteLine((i+1) + ". " + names[i]);

                }

                // wait before closing

                Console.ReadKey();

            }

        }

    }

    [/code]

    Also did a version using List

    [code]

    using System;

    using System.Collections.Generic;


    namespace My_Awesome_Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Write("how many students are in your class?: ");

                int studentCount = Convert.ToInt32(Console.ReadLine());


                Console.WriteLine("Please input the names of the students: ");

                List<string> studentList = new List<string>();

                for (int i = 0; i < studentCount; i++)

                {

                    studentList.Add(Console.ReadLine());

                }

                studentList.Sort();

                for (int i = 0; i < studentList.Count; i++)

                {

                    Console.WriteLine((i+1) + ". " + studentList[i]);

                }

                 // wait before closing

                Console.ReadKey();

            }

        }

    }

    [/code]

  • This is my version. I also added a solution in which instead of a number we enter the word :)

  • COOLCODERCOOLCODER Member
    edited August 21

    Heres my solution for the challenge!


    {

    Console.Title = "ALPHEBETIC ORDER CONVERTER";

    Console.Write("How many students are in your class : ");

    string[] list_students = new string[Convert.ToInt32( Console.ReadLine())] ;

    Console.WriteLine("\nList the students\n-----------------------");


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

    {

    list_students[i] = Console.ReadLine();

    }


    Array.Sort(list_students);


    Console.WriteLine("Heres your sorted list of students");


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

    {

    Console.WriteLine(list_students[i]);

    }

    Console.ReadKey();

    }

    }

    }

  • This is my solution, not too different to brackeys.



    using System;

    using System.Collections.Generic;


    namespace Koding_Projekt

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title = "Dis is le Title";


                Console.WriteLine("How many Students would you like in your class: ");

                int studentCount = Convert.ToInt32(Console.ReadLine());


                Console.WriteLine("Please input the names of the students: ");


                string[] students = new string[studentCount];


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

                {

                    students[i] = Console.ReadLine();

                }


                Array.Sort(students);

                Console.WriteLine("\nHere are your students alphabetically: ");


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

                {

                    Console.WriteLine(students[i]);

                }

                // wait before closing

                Console.ReadKey();

            }

        }

    }

  • using System;

    using System.Collections.Generic;


    namespace tutorial

    {

    class Program

    {

    static void Main(string[] args)

    {

    Console.Title = ".NET Core";

    Console.ForegroundColor = ConsoleColor.Green;

    Console.Write("\n");

    Console.ReadKey();


    List<string> students = new List<string>();


    Console.WriteLine("Enter student names: ");

    string student;

    do

    {

    student = Console.ReadLine();


    students.Add(student);

    } while (student != "exit");


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


    students.Remove("exit");


    students.Sort();


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

    {

    Console.WriteLine(students[i]);

    }


    Console.ReadKey();

    return;

    }

    }

    }

  • using System;


    namespace My_Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                string[] students = new string[4];


                Console.WriteLine("Please input the names of your students: ");


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

                {

                    students[i] = Console.ReadLine();

                }


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

                Console.WriteLine("Here they are in alphabetically: ");


                Array.Sort(students);


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

                {

                    Console.WriteLine(students[i]);

                }


                // Wait before closing

                Console.ReadKey();

     

            }

        }

    }

  • HERES MINE GUYS AND BOIS

    using System;

    using System.Collections.Generic;


    namespace Arrays

    {

    class Program

    {

    static void Main(string[] args)

    {

    Console.BackgroundColor = ConsoleColor.Black;

    Console.ForegroundColor = ConsoleColor.DarkGreen;


    int ammount;

    Console.Write("How many kids are in the class?: ");

    ammount = Convert.ToInt32(Console.ReadLine());


    string[] class_names = new string[ammount];


    Console.WriteLine("what are the names of the students?: ");


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

    {

    class_names[i] = Console.ReadLine();

    }


    Console.WriteLine("\nHere they are alphabeticly: ");


    Array.Sort(class_names);


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

    {

    Console.WriteLine(class_names[i]);

    }


    Console.ReadKey();

    }

    }

    }

  • here's mine

    using System;

    using System.Collections.Generic;

    namespace Array_And_List_thing

    {

        class Program

        {

            static void Main(string[] args)

            {    int number;

                 



                Console.WriteLine("Please write the number of student");

                number = Convert.ToInt16(Console.ReadLine());

                

                  Console.WriteLine("Please input the names of the students: ");

                   string[] students = new string[number];


                   for (int i = 0; i < number; i++)

                   {

                       students[i] = Console.ReadLine();

                   }

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



                Array.Sort(students);



                for (int i = 0; i < number; i++)

                {

                    Console.WriteLine(students[i]);

                }



                

            





                



                //Wait before closing.

                Console.ReadKey();

            }

        }

    }

  • first attempt, struggled a little but i got it working

    using System;

    using System.Collections.Generic;


    namespace My_Awesome_Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.WindowHeight = 40;

                Console.WindowWidth = 100;


                Console.Write("How Many Students Are In Your Class?: ");


                int numOfStudents = Convert.ToInt32(Console.ReadLine());;                      


                Console.WriteLine("What are their name?: ");


                string[] names = new string[numOfStudents];


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

                {

                    names[i] = Console.ReadLine();

                }


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


                Array.Sort(names);


                Console.WriteLine("Here they are alphabeticaly");


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

                {

                    Console.WriteLine(names[i]);

                }


                // Wait before closing

                Console.ReadKey();

            }

        }

    }

  • Aarhhg!!! I don't get it can somebody explain me plz...

  • heres mine i added a total feature




    using System;

    using System.Collections.Generic;


    namespace Array

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title="Wayne's Array";

                

                

                //Getting them to write how many students in class

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.Write("How many Students are in your class: ");


                Console.ForegroundColor = ConsoleColor.Green;

                int studentCount = Convert.ToInt32(Console.ReadLine());


                //student names input

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.WriteLine("Please input the names of your students: ");


                string[] students = new string[studentCount];


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

                {

                    Console.ForegroundColor = ConsoleColor.Green;

                    students[i] = Console.ReadLine();

                }


                //Students result alphabetically

                Console.ForegroundColor = ConsoleColor.Cyan;

                Console.WriteLine("\nHere are you students alphabetically:");


                System.Array.Sort(students);


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

                {

                    Console.ForegroundColor = ConsoleColor.Green;

                    Console.WriteLine(students[i]);

                }

                    Console.WriteLine("Total of: " + studentCount + " Students.");

            

                

                

                

                

                //Wait before Closing

                Console.ReadKey();

            }

        }

    }

  • namespace MyProgramAsANoob

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.ForegroundColor = (ConsoleColor.Green);

                

                Console.WriteLine("How many students are in the class?: ");

                

                string[] students = new string [Convert.ToInt32(Console.ReadLine())];


                Console.WriteLine("Please type their names here: ");

            

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

                {

                    students[i] = Console.ReadLine();

                }


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

                Console.ForegroundColor = (ConsoleColor.Yellow);

                Array.Sort(students);

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

                {

                    Console.WriteLine(students[i]);

                }

                //Wait Before Closing

                Console.ReadKey();

            }

        }

    }

    So when i tried to do this I didn't specifically make a new int.

    Ex. string[] students = new string [Convert.ToInt32(Console.ReadLine())];

    Could this cause an issue? The program ran fine and did what it was supposed to do but i'm just curious whether this is a mistake or just another method?

  • // Here is my program! yay!

    //Pretty spot on to our solution, all that's different is I chose to have the list displayed in yellow for emphasis :)

    //Thanks teach'!


    using System;


    namespace How_Many_Kids_Programs

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title = "Roll Call";



                Console.WriteLine("Hello,\nWelcome to your class organiser.\n\nPlease input number of pupils in your class: ");


                int numberOfKids = Convert.ToInt32(Console.ReadLine());

                string[] children = new string[numberOfKids];


                Console.WriteLine("\nThank You.\nNow please write each pupils name, followed by the 'Return' key: \n");


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

                {

                    children[i] = Console.ReadLine();

                }


                Console.WriteLine("\nHere is your class roll: ");

                

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


                Console.ForegroundColor = ConsoleColor.Yellow;

                Array.Sort(children);


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

                {

                    Console.WriteLine(children[i]);

                }

                Console.ForegroundColor = ConsoleColor.White;


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


                // Wait before closing

                Console.ReadKey();

            }

        }

    }

  • using System;


    namespace my_awsome_program

    {

        class Program

        {

            static void Main(string[] args)

            {Console.WriteLine("how much student are in your class ?");

            

                int names = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("write down the name of your class");


                string[]student = new string[names]; 

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

               {

                   student [i] = Console.ReadLine();

               }

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

    Array.Sort(student);

                

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

    {

        Console.WriteLine(student[i]);

    }

             Console.ReadKey();

            }






        }

    }

  • using System;

    using System.Collections.Generic;

    namespace C_

    {

        class Program

        {

            static void Main(string[] args)

            {

                //For Text Colour

                Console.ForegroundColor = ConsoleColor.Green;


                //Code

                

                Console.WriteLine("How many Students You Want In You're Class?");

                int s=Convert.ToInt16(Console.ReadLine());

                //Making an Array

                string[] students = new string [s];


                Console.WriteLine("Ok Great!!\nNow Enter The Names Of The Students And I'll Sort Them In Alphabetical Order");


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

                {

                    students[i] = Console.ReadLine(); 

                }


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


                Array.Sort(students);


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

                {

                    Console.WriteLine(students[i]);

                }

                

                //pause

                Console.ReadKey();


            }

        }

    }

  • LehipLehip Member
    edited October 15

    I used Lists and made taking names end when "..." is inputted instead of asking how many student to input.


      class Program

        {

            static void Main(string[] args)

            {

                string input = null;

                Console.WriteLine("Please enter the name of the students.\nNOTE: Type '...' and press Enter when you finish typing all of the students."); 


                List<string> studentList = new List<string>();  //Student List


                while (input != "...")

                {

                    input = Console.ReadLine();

                    if (input != "...")

                    {

                    studentList.Add(input);

                    }

                }


                studentList.Sort();

                Console.WriteLine("---------------------\nHere they are alphabetically:");


                for (int i = 0; i < studentList.Count; i++)

                {

                    int order = i + 1;

                    Console.WriteLine(order + ". " + studentList[i]);

                }


                Console.ReadKey(); // Do not close the Console

            }

        }

  • Tow solutions, one w/ Lists and other w/ Arrays .

  • BigEdBigEd Member

    using System;


    namespace lists

    {

        class Program

        {

            static void Main(string[] args)

            {

                // Main

                string[] students = new string[4];


                Console.WriteLine("Type your students names:");

                


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

                {

                    students[i] = Console.ReadLine();   

                }

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

                Array.Sort(students);


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

                {

                    Console.WriteLine(students[i]);

                }






                // Closing

                Console.ReadKey();

            }

        }

    }

  • This is my answer...

    Console.Title = "Teachers Program";

                Console.ForegroundColor = ConsoleColor.Red;

                Console.Write("How many in your class?: ");

                Console.ForegroundColor = ConsoleColor.White;

                string[] students = new string[Convert.ToInt32(Console.ReadLine())];

                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine("What are they're names?");

                Console.ForegroundColor = ConsoleColor.White;

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

                {

                    students[i] = Console.ReadLine();

                }


                Array.Sort(students);

                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine("\nThese are the names in alphabetical order: ");

                Console.ForegroundColor = ConsoleColor.Green;

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

                {

                    Console.WriteLine(students[i]);

                }


                Console.ReadKey();



    I like to make things look good.

  • using System;


    namespace bilal_2nd_program

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.WriteLine("How many students are in your class: ");


                int l = Convert.ToInt32(Console.ReadLine());




                string[] students = new string[l];


                Console.WriteLine("\nPlease enter the name of these " + l + " students: ");


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

                {

                    students[i] = Console.ReadLine();

                } 




                Array.Sort(students);


                Console.WriteLine("\nOK! Following are the names of students in your class:\n");


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

                {

                    Console.WriteLine(i+1 + ". " + students[i]);

                }




                Console.WriteLine("\nThank You!");


                Console.ReadKey();

            }

        }

    }

Sign In or Register to comment.