Tag c switch case

C# Method Parameters

Parameters and Arguments Information can be passed to methods as parameter. Parameters act as variables inside the method. They are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them…

C# Methods

A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions. Why use…

C# Multidimensional Arrays

Multidimensional Arrays In the previous chapter, you learned about arrays, which is also known as single dimension arrays. These are great, and something you will use a lot while programming in C#. However, if you want to store data as…

C# Sort Arrays

Sort an Array There are many array methods available, for example Sort(), which sorts an array alphabetically or in an ascending order: Example // Sort a string string[] cars = {“Volvo”, “BMW”, “Ford”, “Mazda”}; Array.Sort(cars); foreach (string i in cars)…

C# Loop Through Arrays

Loop Through an Array You can loop through the array elements with the for loop, and use the Length property to specify how many times the loop should run. The following example outputs all elements in the cars array: Example…

C# Arrays

Create an Array Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array, define the variable type with square brackets: string[] cars; We have now declared a…

C# Foreach Loop

The foreach Loop There is also a foreach loop, which is used exclusively to loop through elements in an array (or other data sets): Syntax foreach (type variableName in arrayName ) { // code block to be executed } The…

C# For Loop

C# For Loop When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop: Syntax for (statement 1; statement 2; statement 3) { // code block…

C# While Loop

Loops Loops can execute a block of code as long as a specified condition is reached. Loops are handy because they save time, reduce errors, and they make code more readable.