In this video, we're going to look at how we can declare and set array elements in one line.
Okay.
We can set the values for an array.
So therefore I'm going to get rid of this entire stuff and put it in to my new int directly.
And how to do that is I can just say which values I want to have.
So similar to what we did earlier on.
So it was five 1213, 14, 15.
Right.
But here I don't need to say new int, I just need to do the following.
I have the square brackets and inside of the square brackets.
I need to use the data type as is declared here.
I need to use that in here.
So I cannot go ahead and add doubles in here.
That would cause problems, as you can see here.
And I also cannot go ahead and add strings in here okay.
That wouldn't work either.
So it has to be of the same type as I have designed here.
So we're declaring an array and setting or and set the array element values okay.
So here if we now access three we should get the same result as we did earlier.
So we should still get 14 okay.
Because now I just said okay.
At the index three I have 14.
So the indexes again are 0123 and four okay.
So these are the indexes.
And now what I did is I assigned the same value as the index for that position okay.
So now if I access my int array three what am I going to get.
I'm going to get three okay there you are.
So now let's say somebody doesn't start counting at zero.
They start counting at one as we usually do.
We don't start 0123.
We do one two, three, four, five.
You know.
So that's what we have here.
Now if we access index three what are we going to get.
We're going to get four.
So there we are.
It says four okay.
So now a little challenge for you.
Pause the video and declare a string array that contains the weekdays as Mun two wed okay for the weekdays.
So pause the video and create this array real quick.
Okay, I hope you tried it.
So I'm using string, the data type that I want to use, then the square brackets.
And then I'm going to call this one weekdays for example.
Right.
And then inside of the square brackets I'm going to create a bunch of strings.
So in Germany we start the week with Monday.
I think in the US it starts with Sunday, at least in coding in the coding sense so to speak.
Okay.
So I'm going to add the weekdays in here.
And each time they are separated with a comma okay.
And at the end we always have a semicolon as you can see.
All right Wednesday then Thursday I think it's written like this Fri and Sut.
So now we have all weekdays of the week.
So now if I try to access the weekdays let's say I'm going to say today is and then plus weekdays at
position zero.
And it's going to say today is Sunday.
So today is Sunday okay.
I could also very well be that the sun is out or something like that.
But yeah, this is how you can declare an array and set the array values straight away or element values
straight away.
So I'd say let's see how we can use that in order to understand another loop type.
And that is the for each loop.
So see you in the next video.