Hey there! 👋 Welcome to this repository where we explore the exciting world of arrays in C#. Think of arrays as organized boxes where you can store multiple items of the same type. This code demonstrates some fundamental things you can do with these boxes!
This program is like a mini array workshop! It guides you through the following steps:
-
Filling the Boxes 📦: It will ask you to enter ten whole numbers (integers). Each number you type will be placed into one of the ten "boxes" in our array.
-
Getting the Stats 📊: Once all the boxes are filled, the program will do some quick calculations for you:
- Average: It will figure out the average value of all the numbers in the boxes.
- Maximum: It will find the largest number among all the boxes.
- Minimum: It will find the smallest number among all the boxes.
-
Putting Them in Order sıralama: Finally, it will take a copy of your numbers and arrange them in ascending order (from the smallest to the largest). It then shows you the sorted list.
If you have .NET 8 installed on your computer (which seems like you do, great!), running this code is a breeze:
-
Save the Code: Make sure you've saved the code you provided as a file named
Program.csin a folder (let's say you named itArrayManipulation). -
Open Your Terminal: Open your Ubuntu terminal and navigate to the
ArrayManipulationfolder. You can use thecdcommand (change directory). For example:cd ArrayManipulation -
Run the Magic Command: Type the following command and press Enter:
dotnet run
This command tells .NET to build and run your C# code.
-
Follow the Instructions! 📝: The program will then prompt you to enter ten integer values one by one. Just type a number and press Enter after each one. Once you've entered all ten numbers, it will display the calculated average, maximum, minimum, and the sorted list of your numbers.
Here's a simplified breakdown of what's happening in the code:
namespace ArrayManipulation: This is like a main folder that keeps our code organized.class Program: Inside the namespace,Programis the blueprint for our application.static void Main(string[] args): This is the starting point of our program. Everything inside this method is executed when you run the code.int[] numbers = new int[10];: This line creates an array namednumbersthat can hold 10 integer values. Think of it as creating 10 empty boxes next to each other.forloop: This helps us to do something repeatedly. In this case, it loops 10 times to ask you for each number.do-whileloop andint.TryParse(): This is a clever way to make sure you enter a valid whole number. It keeps asking until you type something that can be understood as an integer.CalculateAverage(int[] numbers): This is a separate tool (a method) that takes our array of numbers and calculates their average.FindMax(int[] numbers): This tool goes through the array and finds the biggest number.FindMin(int[] numbers): This tool goes through the array and finds the smallest number.SortArrayAscending(int[] numbers): This tool uses a simple method called "Bubble Sort" to arrange the numbers in increasing order. It compares nearby numbers and swaps them if they are in the wrong order, repeating this until everything is sorted.Console.WriteLine()andConsole.Write(): These are like the program's way of talking to you and displaying information on the screen.Console.ReadKey(): This line makes the program wait for you to press a key before closing the console window, so you have time to see the results.
This is a basic introduction to using arrays in C#. There's a lot more you can do with them, but this gives you a good starting point for storing and working with collections of data! Enjoy experimenting! 😊