So with this lecture, we start a series about collection data structures in C-sharp.
We'll begin with a simple but common question from interviews.
What is a narrow array is the most basic collection easy, sharp.
You can think of an array as a collection of boxes, each one holding a single value.
Each box has its index starting at zero and ending at our linked minus one.
The important thing to understand is that whilst an error has been created, its size cannot be changed.
Because of that, errors are not the best choice if the collection that we need is going to grow or
shrink over time.
If we try to get or set the value at an index, that's not Indira, we'll get index out the French exception.
This line will throw an exception because in the stern, it's not in the euro.
The last index is for when an aura is created.
It is filled with the default values for the given type.
For example, an array of incense will be filled with zeros and an array of strings will be filled with
Norse.
We can set the values of the aura right at the moment of initialization, using the collection equalizer.
In this case, we don't need to specify the RSI as it will be said to the count of provided elements.
This gold will naturally create an aura of south free arrows can store and the objects of the same type,
they can be single dimensional, multidimensional or dagat.
For example, this is a single dimensional array that holds five inks.
We can also define multidimensional arrays that resemble tables or mattresses that we know from mathematics.
This is a two dimensional array that can hold up to 15 months.
The data held in this array could be visualized like this.
We can think of are multidimensional array as an array of arrays, which all have the same length.
In this case, we have an array of size free and each index there is an array of size five to get or
set an element of our multidimensional array, you must simply use two indexes instead of one separated
by a comma.
We can also define jagged arrows are jagged arrow is an array of arrows which don't need to be of the
same length.
Let's define a jagged array of integers.
Here we defined an array of size free for which each element will be an array of ins.
Let's set those elements.
In this case, the structure of this Typekit arrow will look like this.
At Index Zero, we have an array of links to add index one of them at one and at index to offload three.
Please notice the difference in accessing the elements of a drug array in opposition to a multi-dimensional
array in the case of drug arrow.
We must use two sets of buckets before we continue.
Quick information for people with a background in languages like C or C++.
Remember that in C-sharp, an arrow is just an object and the others it's not on addressable region
of memory, like in those of our languages.
Arrows are reference types in C Sharp.
All right.
Let's see what arrows are best for and when we should rather consider using other collection types.
First of all, arrows are the most basic and native collection type.
They represent the data in a way that is very close to how the data is stored in the computer's memory.
Many of our collections like, for example, lists we learn about in the next lecture use arrows as
their underlying data structures.
Arrows as the most native collection type have the advantage of being fast.
We can get or set an element of the given index in a constant time so super fast in less technical terms.
When we care about the performance, arrows are often the best choice.
Also, multidimensional arrows are commonly used in mathematical operations as they represent matrices
very well.
They're also very useful whenever we need to represent a multi-dimensional structure.
Think of our two dimensional game we styled map like chess or snake.
The two-dimensional array of tiles would probably be the most natural and performance efficient ways
to represent the game area.
The disadvantage of using arrows is that their size is fixed.
In other words, it's not a dynamic collection.
We can't really add or remove elements from it.
We could assume that some size of an arrow is large enough for our needs.
Let's work on an e-commerce platform, and we want to store the items culled in the shopping cart in
an array.
We can declare an array of sites 100 and hope.
No one will buy more items, but such assumptions are dangerous.
What if someone is in a shopping rage and they really wants to buy more things?
OK, so let's set the size to 1000, but done in 99 percent of the cases will allocate the memory for
1000 items.
Well, actually only two or three will be added.
This is a huge waste.
So in short, our eyes are great if we know the count of elements upfront, but not so much.
If we do not during the interview, you can have questions like what is a are a drug?
It already is an array of arrays which can all be of the different lengths.
What are the advantages of using arrays?
They are fast when it comes to accessing an element of the given index.
They are basic and easy to use and great for representing simple data of size that is known upfront.
So what are the disadvantages of using race?
Arrows are a fixed size, which means once created, they can't be resized.
It means they are not good for representing dynamic collections that grow or shrink over time.
If we want to allocate the memory for all elements that may be stored, there is a chance that we allocate
too much and waste it.
We can also underestimate and not declare an error big enough for some add cases.
How to resize an array?
Well, it's not possible.
An arrow is a collection of a fixed size and once created, it cannot be resized.
All right, that's it about race.
Thanks for watching and see you in the next video.