When I explained functions and methods parameters, I said that we can use them to send different values that our methods and functions can use in their calculations. You should also know that methods and functions can have optional parameters, parameters with a default value, which can be skipped when calling a method or function.… Read more
Archive for April, 2017
Optional parameters
Sunday, April 16th, 2017Execution workflow
Saturday, April 15th, 2017Whenever a method executes, it takes control over execution workflow of the program. However, if in the caller method we call yet another method, the execution is transferred to this new method, until it’s code is executed, and when that finishes, the execution control is returned to the first calling method.… Read more
Variable Scope
Saturday, April 15th, 2017A very important concept in programming is what we call variable scope. Though this concept should have been explained when I explained variables, it wouldn’t have made much sense back then, because it was relying on stuff we did not yet explain.… Read more
Methods and functions parameters
Tuesday, April 11th, 2017Our methods and functions can perform different actions, but sometimes, we need to offer them certain relevant data to process. We do this by using methods and functions parameters.
One of the primary goals of methods and functions is what we call code re-usability and this means we don’t have to copy and paste the same piece of code over and over, whenever we need that certain action to be performed.… Read more
Methods and functions declaration
Sunday, April 9th, 2017Methods and functions declarations is actually a three step process: declaration, implementation, call of our method or function.
- Declaration is the process of writing the method type, name and eventual parameters, so the program can successfully identify it.
- Implementation of a method is writing the actual code that will be executed when the method is executed.
Functions
Saturday, April 8th, 2017Every person that ever wanted to become a programmer was at some point discouraged by one of the few things that makes programming so hard: its complexity. Whenever someone would want to code something like Skype, for instance, they would first of all feel overwhelmed about the incredibly complex task they face.… Read more
Test your knowledge! – Arrays
Friday, April 7th, 2017Arrays of arrays
Friday, April 7th, 2017C# allows us to have arrays of arrays, which we call jagged arrays. An array of arrays is basically an array in which each row is actually another array on its own.
This is an example of declaration for an array of arrays:
1 2 3 4 5 |
int[][] arrayOfArrays; arrayOfArrays = new int[3][]; arrayOfArrays[0] = new int[3]; arrayOfArrays[1] = new int[7]; arrayOfArrays[2] = new int[4]; |
and this is how we initialize it:
1 2 3 4 5 6 |
int[][] arrayOfArrays = { new int[] {1, 7, 2}, new int[] {2, 3, 1}, new int[] {6, 45} }; |
Also, the arrays of the array can be one dimensional or multi-dimensional arrays, like we learned:
1 2 3 |
int[][,] arrayOfArrays = new int[2][,]; arrayOfArrays[0] = new int[,] { { 5, 15 }, { 125, 206 } }; arrayOfArrays[1] = new int[,] { { 3, 4, 5 }, { 7, 8, 9 } }; |
Finally, getting or setting the elements of an array of an array (lol, that sounds so complicated 😐 ):
1 |
arrayOfArrays[0][2] = 28; |
Most of the times, arrays of arrays won’t be of a real use to you, there are simpler ways of doing this.… Read more
Multidimensional arrays
Wednesday, April 5th, 2017In mathematics, one-dimensional arrays are also known as vectors. Some of you may still remember (riiight! 🙂 ) that multidimensional arrays are called matrices. In programming, we call multidimensional arrays any array with more than one dimension.
For instance, how would we represent the structure of a chess board programmatically?… Read more
Iteration through the elements of an array
Wednesday, April 5th, 2017Iteration through the elements of an array is basically the way we access all the elements of an array, in an automated way. The first type of loop we will exemplify is the For loop.
It is always a good practice to use a for loop whenever you deal with an array or any other structure with indices.… Read more