ArrayList is a dynamic array. What that means is that an ArrayList can have any amount of objects and of any type. This data structure was originally designed to simplify the processes of adding new elements into an array. Under the hood, an ArrayList is an array whose size is doubled every time it runs out of space.… Read more
Posts Tagged ‘arrays’
Array List
Monday, April 23rd, 2018Arrays
Friday, April 20th, 2018Test 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
Accessing the elements of arrays
Tuesday, April 4th, 2017As I was explaining in a previous post, arrays can be seen as a building (the array itself) with apartments (the elements of the array), each identified by an apartment number (the indices or the array elements). So, accessing the elements of arrays is done through their elements indices, just like finding an address is done through the apartment number inside a building.… Read more
Initialization of arrays
Friday, March 31st, 2017Like any other variables, arrays must be initialized before we can access and use an element of that array. In C#, initialization of arrays is done automatically with default initial values. For numeral types, the default initialization value is 0, False for bool type, null for reference types, etc.… Read more
Declaration of arrays
Thursday, January 19th, 2017When we are dealing with declaration of an array, you should always remember that arrays in C# are fixed length. Their length is set at the time we instantiate them, it determines the total number of elements that they can store, and it cannot be changed/resized anymore.… Read more
Arrays
Wednesday, January 18th, 2017You’ve made it this far! Well done! Starting with arrays, we can already say we have a very basic knowledge of C# programming. Still a long path ahead of us, but we are no longer n00bs. We now know the fundamental things of (almost) any programming language and we can write basic programs.… Read more