1
00:00:01,030 --> 00:00:02,280
Hey guys welcome back.

2
00:00:02,280 --> 00:00:06,730
In this video we'll be looking at areas and collections in C sharp.

3
00:00:07,830 --> 00:00:15,630
No I said areas and collections because well our Ari is the most widely used type of collection in most

4
00:00:15,630 --> 00:00:17,260
if not all languages.

5
00:00:17,280 --> 00:00:24,920
So my understanding honoree in C sharp you can apply pretty much the same concepts to C++ Java and all

6
00:00:25,020 --> 00:00:26,940
other programming language.

7
00:00:26,940 --> 00:00:34,860
That being said however there are other kinds of collection data types that exist and b since we are

8
00:00:34,860 --> 00:00:40,920
using C sharp we be looking to areas and we'll also be looking at lists and then I'll give you a sneak

9
00:00:40,920 --> 00:00:42,740
peek at the others.

10
00:00:42,750 --> 00:00:48,510
But the reality is that they all kind of behave the same way and I've been on the day it's almost a

11
00:00:48,510 --> 00:00:53,190
matter of preference which one you will choose no to get started.

12
00:00:53,190 --> 00:00:55,650
I'm going to ask you to just pause right here.

13
00:00:55,650 --> 00:01:01,440
Go ahead and create your new project in your solution called arrays and collections and once you've

14
00:01:01,440 --> 00:01:03,900
done that then you can continue in the video.

15
00:01:04,020 --> 00:01:11,760
So let's take some time to define an array and then just put in some visual guides in the form of comments

16
00:01:11,790 --> 00:01:18,840
so that we know exactly what we'll be accomplishing as we go along but an array is a collection of objects

17
00:01:18,840 --> 00:01:20,310
of the same data type.

18
00:01:20,320 --> 00:01:26,390
Or if you wanted a big word to use or do you see it's a homogenous collection of data.

19
00:01:26,670 --> 00:01:35,460
So that really means that you can have a bunch of numbers all directly related to each other or a bunch

20
00:01:35,460 --> 00:01:41,700
of strings all they're related to each other and all the advantage to using an array instead of variables

21
00:01:41,700 --> 00:01:48,300
that we've been using up until this point would be that if I wanted a program to predict the grades

22
00:01:48,300 --> 00:01:57,210
for 10 students in a class all right I would have to declare 10 variables that would be Grade 1 grade

23
00:01:57,210 --> 00:02:04,350
to grade three through ten to collect ten grades instead of doing that however I can declare an every

24
00:02:04,560 --> 00:02:13,080
four 10 hour so we're going to get started with our first array by the clearing an array to store five

25
00:02:13,080 --> 00:02:15,260
grades for some students are at.

26
00:02:15,270 --> 00:02:21,710
So once again if we wanted to store five years origin originally would have been declaring five variables

27
00:02:21,720 --> 00:02:24,410
grade one grade to grade through Grade Four at five.

28
00:02:24,630 --> 00:02:30,990
However we can actually see the data type which in this case would be something like int it for certain

29
00:02:31,020 --> 00:02:31,430
grades.

30
00:02:31,440 --> 00:02:37,290
In this fine and then we would have square brackets that indicates that we want an array.

31
00:02:37,320 --> 00:02:42,150
So we want an array or collection of integers.

32
00:02:42,630 --> 00:02:44,190
Then we give our array a name.

33
00:02:44,190 --> 00:02:52,020
So in this case like I said we're studying grids so inch square brackets grids and then we have to initialize

34
00:02:52,020 --> 00:02:52,130
it.

35
00:02:52,140 --> 00:02:56,310
So we say is equal to a new INT.

36
00:02:56,310 --> 00:03:02,320
And then while this is the sexual we're doing a fixed size area so we know that we want five grades.

37
00:03:02,340 --> 00:03:05,400
So inside of the square brackets are going to see five.

38
00:03:05,940 --> 00:03:06,300
All right.

39
00:03:06,570 --> 00:03:12,560
And then the semicolon so you see that this initialization kind of looks a little bit like call we initialize

40
00:03:12,570 --> 00:03:15,790
our classes right into objects sorry.

41
00:03:16,020 --> 00:03:25,110
So we have the data type and the re the square brackets indicate that it's on our race it looks just

42
00:03:25,110 --> 00:03:30,570
like a variable declaration really except where initializing it like what we did it with the objects

43
00:03:30,570 --> 00:03:31,590
and world class.

44
00:03:31,620 --> 00:03:39,700
So we say give me a collection of integers and I want up to five OK.

45
00:03:40,030 --> 00:03:46,060
So now that we have it declared we can start assigning values and there are a few ways to do that but

46
00:03:46,090 --> 00:03:52,120
we'll do that later on in this section where we assign both fixed theory but then you see that I have

47
00:03:52,120 --> 00:03:55,980
a fixed every section and then I have a variable size resection.

48
00:03:56,020 --> 00:04:01,260
So this is when I know that I have five grades.

49
00:04:01,360 --> 00:04:02,380
So coding.

50
00:04:02,700 --> 00:04:03,320
All right.

51
00:04:03,420 --> 00:04:09,120
No actually I'm went to rearrange it so I'm going to try and do each one in its own section.

52
00:04:09,200 --> 00:04:14,500
Someone just show you how to initialize an array when you don't necessarily know how many you're going

53
00:04:14,500 --> 00:04:19,480
to have and the numbers into variance should come in so that they can do with a fixed size one time

54
00:04:19,480 --> 00:04:26,710
and then the variable size at another point but pressing ahead when I don't necessarily know how many

55
00:04:26,710 --> 00:04:27,980
grades to expect.

56
00:04:27,970 --> 00:04:28,300
Right.

57
00:04:28,300 --> 00:04:34,630
So if you're building this application maybe to sell to various schools some schools may have 10 students

58
00:04:34,630 --> 00:04:43,090
some have fired some of 20 you don't want to put in a fixed size because you can't go above the fixed

59
00:04:43,090 --> 00:04:50,830
size and if you go any less than the fixed size then you're basically wasting space because it is going

60
00:04:50,830 --> 00:04:55,710
to reserve five spaces in memory for grades.

61
00:04:56,020 --> 00:05:02,470
So this time I'm just going to say it's grades and I'm going to call this one grades 1 and remember

62
00:05:02,740 --> 00:05:06,910
I recently in square brackets grades 1 and then semicolon.

63
00:05:06,910 --> 00:05:13,180
So right here I'm saying that I want an r re and I'm not necessarily sure how much space I'm going to

64
00:05:13,180 --> 00:05:16,170
need for this area but just know that I need NRT.

65
00:05:16,170 --> 00:05:16,470
All right.

66
00:05:16,780 --> 00:05:20,840
So I'm just going to just give me a moment that me organize this.

67
00:05:20,920 --> 00:05:21,280
All right.

68
00:05:21,310 --> 00:05:24,790
So I just did a quick crew organization off the comments.

69
00:05:24,790 --> 00:05:27,670
If you didn't read the comments that's fine I'm just doing it as a result.

70
00:05:27,680 --> 00:05:32,010
It's a we can be clear as to what activity we're completing at which point.

71
00:05:32,230 --> 00:05:39,610
So when we're dealing with an R RI off a fixed size what happens once again is that we have to declare

72
00:05:40,000 --> 00:05:48,790
how much space we need know to assign values to this area I have two options I can either see the uranium

73
00:05:48,910 --> 00:05:52,030
which is grades and then choose the subscript.

74
00:05:52,360 --> 00:06:01,150
So what happens is that by seeing five we have reserved five spaces in memory for this three or four

75
00:06:01,150 --> 00:06:03,350
the values that should be going into this area.

76
00:06:03,490 --> 00:06:10,510
So then our address is for the values would be what we call a subscript.

77
00:06:10,580 --> 00:06:11,180
Right.

78
00:06:11,230 --> 00:06:20,710
So each subscript has a speak a name and they start from zero and they go up to one less than the size.

79
00:06:20,710 --> 00:06:23,370
All right so let me just write a comment explaining that.

80
00:06:23,920 --> 00:06:32,260
So when you have five spaces it means that you have addresses zero through four.

81
00:06:32,260 --> 00:06:40,150
So address zero is one then one is then the second space then two is the third space three is the fourth

82
00:06:40,150 --> 00:06:42,900
space and then four is the fifth space.

83
00:06:42,940 --> 00:06:47,170
So in our is zero is very very very valuable.

84
00:06:47,530 --> 00:06:47,980
All right.

85
00:06:48,220 --> 00:06:54,700
So you know in regular math you may not code zero as a speech but in computer zero is the very first

86
00:06:54,700 --> 00:06:55,490
space.

87
00:06:55,540 --> 00:07:03,610
So technically if mathematically if you will have an array of size 10 then you're going to go from zero

88
00:07:03,760 --> 00:07:11,090
to nine or whatever size you declare it is basically zero to end minus one where n is the size.

89
00:07:11,120 --> 00:07:11,480
All right.

90
00:07:11,560 --> 00:07:12,880
That's a little formula.

91
00:07:12,880 --> 00:07:20,170
All right said in another comment If n is the size of the array then your area addresses are 0 2 and

92
00:07:20,170 --> 00:07:20,920
minus 1.

93
00:07:20,920 --> 00:07:28,630
So once again if a 5 is the size then we have zero to five minus 1 which is 4.

94
00:07:28,660 --> 00:07:29,040
All right.

95
00:07:29,260 --> 00:07:34,600
So to assign the values then I would just call each one by its specific address.

96
00:07:34,600 --> 00:07:40,390
So if I wanted to put something in the first one then I say grid's square brackets putting zero as a

97
00:07:40,390 --> 00:07:44,200
subscript or the address and then I would see equals.

98
00:07:44,200 --> 00:07:45,400
That's a one.

99
00:07:45,460 --> 00:07:45,820
All right.

100
00:07:46,180 --> 00:07:52,650
So that's the first grade and then I'm just going to duplicate this to speed it up so I can see grades

101
00:07:53,050 --> 00:07:57,970
subscript 1 subscript 2 subscript 3 subscript 4.

102
00:07:57,970 --> 00:07:58,490
All right.

103
00:07:58,570 --> 00:08:03,430
And then I can just assign the different values here.

104
00:08:03,680 --> 00:08:06,890
So we have some students doing well and some important.

105
00:08:06,890 --> 00:08:07,510
That's fine.

106
00:08:08,480 --> 00:08:08,750
All right.

107
00:08:08,750 --> 00:08:17,120
So another way that you can assign values would be to see grades is equal to and then you have to declare

108
00:08:17,120 --> 00:08:22,870
that you are sending a new every and then the use of curly braces sorry.

109
00:08:22,890 --> 00:08:29,200
And you into area for the data type so I have to say new and then the data type of the type of rape.

110
00:08:29,330 --> 00:08:33,920
So of course if I put a different data type here I'm going to get an error because we already declared

111
00:08:34,190 --> 00:08:38,050
that grades is an integer area type.

112
00:08:38,060 --> 00:08:38,390
Right.

113
00:08:38,390 --> 00:08:44,200
So that's what we mean by it's homogenous in an area kind of stirring strings and integers.

114
00:08:44,270 --> 00:08:44,800
All right.

115
00:08:44,840 --> 00:08:47,180
It has to be one at a time.

116
00:08:47,240 --> 00:08:55,140
So I would say grades and then new and then the ins with the curve with the square braces.

117
00:08:55,250 --> 00:08:59,170
And then in the current braces then I can spell out the values.

118
00:08:59,180 --> 00:09:05,750
So if I wanted so score 0 to have a particular value which in this case I would put 10 and then comma

119
00:09:06,020 --> 00:09:10,640
and then 20 comma 30 comma for it to come a 50.

120
00:09:11,000 --> 00:09:19,760
All right so no I have one two three four five values and then they kind of implicitly assign them to

121
00:09:19,760 --> 00:09:21,170
the appropriate address.

122
00:09:21,200 --> 00:09:22,570
So this is the first value.

123
00:09:22,690 --> 00:09:24,750
It will go into subscript zero.

124
00:09:24,800 --> 00:09:28,000
So I'm setting values here and then I'm setting values here.

125
00:09:28,010 --> 00:09:33,650
What I'm really doing is overwriting these values with this setup right here.

126
00:09:33,680 --> 00:09:38,690
All right so I don't mean to confuse them just showing you that we could have done it this way and we

127
00:09:38,780 --> 00:09:45,130
also could have initialized the three that we write so I can actually just comment.

128
00:09:45,170 --> 00:09:46,930
Well whichever one you want to come in.

129
00:09:47,270 --> 00:09:51,110
No the danger would be in assigning an extra one.

130
00:09:51,140 --> 00:09:57,440
So if I had put in an extra value without putting an extra address like that's it grades five and then

131
00:09:57,440 --> 00:10:06,980
gave it to another value or I or I said come on 60 here I said I have five addresses but I'm assigning

132
00:10:06,980 --> 00:10:08,510
six values.

133
00:10:08,510 --> 00:10:15,220
One two three four five six are counting here one two three four five six.

134
00:10:15,320 --> 00:10:16,640
That's going to be a problem.

135
00:10:16,930 --> 00:10:23,180
And if I attempt to I'm going to execute this and show you the problem that we're going to run into.

136
00:10:23,840 --> 00:10:29,270
All right so all I do was execute and then it's telling me that I have a system that index all its offerings

137
00:10:29,330 --> 00:10:30,390
exception.

138
00:10:30,470 --> 00:10:36,680
So they're telling me that this index was outside its index is another word for subscript R address.

139
00:10:36,680 --> 00:10:36,920
Right.

140
00:10:37,250 --> 00:10:40,050
So this index was outside the bones of the array.

141
00:10:40,070 --> 00:10:45,790
So once again if you set it for five then you're expected to have no more than five.

142
00:10:45,800 --> 00:10:49,120
You can have fewer but no more than art.

143
00:10:49,160 --> 00:10:55,970
So that is how strict areas are when they are assessing the data that is being put in.

144
00:10:56,180 --> 00:11:06,080
I'm just going to remove these values that will would throw an arrow no less of a dimension to assigning

145
00:11:06,080 --> 00:11:14,420
values to an area would be the fact that you wouldn't sit down and you know hard core these voters like

146
00:11:14,450 --> 00:11:20,060
the scenario game initially was that you're building a program to give to a school or some institution

147
00:11:20,420 --> 00:11:29,240
to be able to collect the values from what the program is going to allow the users to input the values

148
00:11:29,240 --> 00:11:30,380
into the Ari.

149
00:11:30,380 --> 00:11:30,770
All right.

150
00:11:31,040 --> 00:11:34,550
So we already know how to inputs we already know how to Oakwood.

151
00:11:34,670 --> 00:11:42,040
We already know how to store values inside of a variable when we allow the user to input data.

152
00:11:42,050 --> 00:11:45,290
So we just want to extend that knowledge of beats to the RV.

153
00:11:45,320 --> 00:11:51,780
So if I told an institution that if they have five students I could give them a program somebody is

154
00:11:51,800 --> 00:11:58,430
going to come in these lines oats those are no examples but I'm giving them a program that they can

155
00:11:58,520 --> 00:12:02,660
at will put in their five students.

156
00:12:02,660 --> 00:12:03,200
All right.

157
00:12:03,860 --> 00:12:12,470
So what I would want to do then is have something like a for loop so I could save for normal loops and

158
00:12:12,470 --> 00:12:16,010
a for loop is basically perfect for an hour.

159
00:12:16,040 --> 00:12:17,710
So let's go through this together.

160
00:12:17,790 --> 00:12:22,760
Someone to save for int is equal to zero.

161
00:12:22,760 --> 00:12:25,960
And remember that all areas start going thing at zero.

162
00:12:25,970 --> 00:12:26,330
Right.

163
00:12:26,660 --> 00:12:32,870
So I starts off with a value of zero and then I'm going to say I want this program or this for little

164
00:12:32,880 --> 00:12:36,380
brother to run for less than five.

165
00:12:36,410 --> 00:12:41,990
So remember that if we say less than five we will run from zero to five minus one.

166
00:12:41,990 --> 00:12:46,670
That sounds very familiar at zero to five minus one.

167
00:12:46,670 --> 00:12:47,020
All right.

168
00:12:47,510 --> 00:12:52,990
And then I will say I want I increment after each run.

169
00:12:53,030 --> 00:13:01,330
So this for loop is going to help us to do is go through each of the the subscript or the index is up

170
00:13:01,330 --> 00:13:03,830
for every quite weekly right.

171
00:13:04,840 --> 00:13:05,130
All right.

172
00:13:05,140 --> 00:13:10,720
So I just wrote in to console that red line still very easily answer at this point.

173
00:13:10,710 --> 00:13:14,070
That shouldn't be very hard for a second pause the video.

174
00:13:14,070 --> 00:13:14,970
Write them off.

175
00:13:15,210 --> 00:13:18,800
But then what I'm doing here is just prompting the use of something.

176
00:13:18,810 --> 00:13:22,530
Enter a student grades that I'm just seeing console right.

177
00:13:22,530 --> 00:13:27,840
So this is a right line where it would break the line and then the right is what would happen for as

178
00:13:27,840 --> 00:13:29,730
many times as the loop is run.

179
00:13:29,730 --> 00:13:31,280
So if I run it right.

180
00:13:31,290 --> 00:13:40,410
No is going to ask you to enter the grade 510 CTC enter student grades and then the right integrated

181
00:13:40,440 --> 00:13:43,950
integrate integrate integrate off course the write those and the line.

182
00:13:43,980 --> 00:13:45,240
So that's why I did that.

183
00:13:45,240 --> 00:13:48,020
However all the data was sprints.

184
00:13:48,030 --> 00:13:51,990
Obviously that's not what we're here for we wanted to actually pause.

185
00:13:51,990 --> 00:13:56,300
Allow me to input the grade maybe press enter and then it proceeds.

186
00:13:56,310 --> 00:13:57,000
Right.

187
00:13:57,060 --> 00:14:07,000
So what I would do here is one say that I want the grade with the index of what ever value I has.

188
00:14:07,020 --> 00:14:15,090
So remember if I starting off a zero and all three start off at zero then instead of seeing grade with

189
00:14:15,090 --> 00:14:21,030
a hard coded index here like we did when we set Grade Zero is this period 1 is that group 2 is that

190
00:14:21,030 --> 00:14:21,730
blah.

191
00:14:21,960 --> 00:14:27,030
We can actually just see agreed with the subscript our index value of i.

192
00:14:27,270 --> 00:14:32,250
So that means whatever value I has at the time that the for loop is running.

193
00:14:32,250 --> 00:14:40,110
That is the index inside of the three that I want to manipulate and the manipulation here would be to

194
00:14:40,110 --> 00:14:41,160
accept input.

195
00:14:41,160 --> 00:14:48,780
So of course you know that to accept inputs to console read the line all right.

196
00:14:48,780 --> 00:14:52,450
And then because greed is an integer.

197
00:14:52,450 --> 00:14:53,200
Right.

198
00:14:53,200 --> 00:14:55,530
Oh sorry it's not green but grids my.

199
00:14:55,900 --> 00:15:01,380
So grids represents an integer we're getting that red line so we we need to pass.

200
00:15:01,410 --> 00:15:08,410
So we say in that hires what ever value we get from the console.

201
00:15:08,410 --> 00:15:09,280
All right.

202
00:15:09,350 --> 00:15:15,150
So once again we're just seeing enter grid and then we pause for inputs.

203
00:15:15,160 --> 00:15:16,910
That's what this line is doing.

204
00:15:16,960 --> 00:15:21,010
So a possible input to the console that read line when the person presses enter.

205
00:15:21,040 --> 00:15:28,750
Then we pass it to be an integer and then having passed it we assign it to the corresponding index in

206
00:15:28,750 --> 00:15:31,960
the area based on the value that I has.

207
00:15:31,960 --> 00:15:40,700
So this now allows us to run from zero to whatever value we put there which if it's and then it's N

208
00:15:40,720 --> 00:15:42,030
minus one.

209
00:15:42,070 --> 00:15:42,400
All right.

210
00:15:42,430 --> 00:15:43,880
So let's try that.

211
00:15:44,590 --> 00:15:45,010
All right.

212
00:15:45,040 --> 00:15:51,130
So we see here that we printed the console the right line integrates and then where it's integrated.

213
00:15:51,160 --> 00:15:54,100
This is the first run and then it's waiting.

214
00:15:54,130 --> 00:15:57,490
So I'm going to put 10 then when I press enter it runs again.

215
00:15:57,490 --> 00:16:00,920
No it's counted up no eyes 1.

216
00:16:00,930 --> 00:16:06,640
So I'm 20 and 30 then 40 and then 50.

217
00:16:06,640 --> 00:16:12,560
That's 1 1 7 2 3 4 5 values.

218
00:16:12,610 --> 00:16:16,940
And then when I press enter we see that it stops running.

219
00:16:16,960 --> 00:16:17,530
All right.

220
00:16:17,950 --> 00:16:22,590
So that is how we dynamically accept values into the area.

221
00:16:22,600 --> 00:16:28,120
And as you can see it's kind of in a straight line zero to the end it's not put in the first one then

222
00:16:28,120 --> 00:16:31,220
the third one then maybe the fourth one then go back to the second one.

223
00:16:31,220 --> 00:16:34,150
No it's from start to finish right.

224
00:16:34,750 --> 00:16:38,490
No that was just inserting the values into the grid.

225
00:16:38,500 --> 00:16:43,960
So by the end of this fall to all of the values that have been stored instead of grids similar to that

226
00:16:43,990 --> 00:16:48,140
but of course not higher quality would be relative to whatever the user would have put you know at the

227
00:16:48,130 --> 00:16:48,810
time.

228
00:16:48,970 --> 00:16:49,450
No.

229
00:16:49,570 --> 00:16:54,240
When the person in time they're finished I'm sure they'd want to see the grades that they entered.

230
00:16:54,250 --> 00:16:57,650
So I'm just going to copy this code.

231
00:16:57,670 --> 00:16:58,630
All right.

232
00:16:58,690 --> 00:17:03,130
Because then the for loop allows us to go back through the Ari again.

233
00:17:03,130 --> 00:17:13,930
So instead of writing Enter Grades I'm going to see the grades you entered are or were.

234
00:17:13,960 --> 00:17:24,040
Well I can leave that and then I'm going to see instead of pausing for inputs I'm just going to create

235
00:17:24,040 --> 00:17:31,320
all this for loop altogether and then what I'm going to see in this for loop is console dots rights

236
00:17:31,350 --> 00:17:41,820
line and then I want to write the value that is inside of each subscript of my grades I read.

237
00:17:42,150 --> 00:17:42,540
All right.

238
00:17:42,870 --> 00:17:49,010
So then each line is just going to print OK whatever value I has at the time.

239
00:17:49,080 --> 00:17:50,340
That's the value is going to print.

240
00:17:50,340 --> 00:17:52,570
So let's try that again.

241
00:17:52,690 --> 00:17:58,580
All right so norm when to enter the grids and I'm going to be a bit more vague this time so can see

242
00:17:58,580 --> 00:18:06,170
I'm not urging it so I'm putting in random grids 50 into a 46 38 52 and 30 and then we print all the

243
00:18:06,170 --> 00:18:14,470
greats of the grades you entered are in the exact order that they were entered right for all five.

244
00:18:14,470 --> 00:18:20,390
Now if you don't write your for loop properly and then you end up trying to put in an extra grid here

245
00:18:20,600 --> 00:18:27,110
in the area 5 or the fixed size 3 then it will give you one of those old bones that are safe you are

246
00:18:27,100 --> 00:18:28,590
seeing on Audubon's arrows.

247
00:18:28,730 --> 00:18:35,050
It means that you are trying to reference an index that does not exist based on your declaration of

248
00:18:35,060 --> 00:18:35,780
your Ari.

249
00:18:36,500 --> 00:18:36,730
All right.

250
00:18:36,740 --> 00:18:40,290
So know that we looked at how we deal with the fixed size.

251
00:18:40,330 --> 00:18:46,510
Ari let us take a look at how we deal with the variable size our severe variables mean that they're

252
00:18:46,520 --> 00:18:51,230
prone to change or they're basically unknown until a certain situation.

253
00:18:51,230 --> 00:18:57,290
So when we see the variable size it means that I'm giving this program to a school that I don't know

254
00:18:57,290 --> 00:19:01,390
the number of students that have that one or the number of grades that f the input.

255
00:19:01,400 --> 00:19:05,810
So I can't be as rigid as seeing five right or ten or one hundred.

256
00:19:05,810 --> 00:19:11,360
I don't want to say a hundred thousand when there were 50 students and then the computer crashes on

257
00:19:11,390 --> 00:19:13,550
the pressure when it really didn't tough to write.

258
00:19:14,030 --> 00:19:19,880
So what I'm doing here is saying that OTM I know I need an RE I don't know what size it's going to be

259
00:19:20,300 --> 00:19:27,440
but then later on you know based on the size are based on the values that they're putting then I can

260
00:19:27,440 --> 00:19:33,680
make that determination so that every declaration are assigned to every assignment value assignment

261
00:19:34,100 --> 00:19:40,400
in this situation would more model this one right where we just copied and pasted so that we can see

262
00:19:40,400 --> 00:19:42,290
it within its context.

263
00:19:42,290 --> 00:19:44,350
And we're talking about grades 1.

264
00:19:44,480 --> 00:19:44,750
Right.

265
00:19:45,080 --> 00:19:51,260
So because we didn't give it a size initially I can see grades one is equal to.

266
00:19:51,530 --> 00:19:58,220
And whatever is in the curly brace whatever number of values I put in it will accept that as its size.

267
00:19:58,220 --> 00:20:01,400
So if I put in five then it knows it's an aerial size five.

268
00:20:01,550 --> 00:20:08,810
If I put in 10 all right so those put in five more values looks cheap but lets us work with it.

269
00:20:08,960 --> 00:20:11,540
Then it knows that its size is no 10.

270
00:20:11,570 --> 00:20:13,660
So that's why would call it a variable size.

271
00:20:13,660 --> 00:20:14,440
I agree.

272
00:20:14,450 --> 00:20:15,930
All right.

273
00:20:16,220 --> 00:20:25,160
Know unfortunately based on the nature of these dynamically sized Ari's the based on the strict nature

274
00:20:25,160 --> 00:20:31,630
of Ari's actually it is kind of difficult to actually dynamically assign values.

275
00:20:31,630 --> 00:20:38,120
So after you've defined it it's see they define it here in this land where what I said is equal to a

276
00:20:38,120 --> 00:20:45,210
new into all of this or I would define it here but then you know putting it in a for loop on populating

277
00:20:45,210 --> 00:20:46,040
it like that.

278
00:20:46,040 --> 00:20:47,720
It's kind of more difficult.

279
00:20:47,720 --> 00:20:54,880
So I actually see Shah use those other collection types and one such type is a list.

280
00:20:55,160 --> 00:20:55,760
All right.

281
00:20:55,790 --> 00:21:02,600
So I'm going to use this opportunity you know to show you the list so I'm really and truly printing

282
00:21:02,600 --> 00:21:07,430
diaries in the variable printing the value sorry and the variable error is very similar.

283
00:21:07,670 --> 00:21:15,410
So we just do that quickly where I'm just going to take this code from the previous already and then

284
00:21:15,410 --> 00:21:22,020
what we can do is actually see something like the Iranian which is grades 1 and then I can see a dot

285
00:21:22,370 --> 00:21:24,190
and then see it at length right.

286
00:21:24,200 --> 00:21:32,150
So by seeing grids 1 dots length I am seeing that I'm not sure how many volumes are here but whatever

287
00:21:32,270 --> 00:21:36,900
number of values there are which is depicted by the volume length.

288
00:21:36,920 --> 00:21:37,180
All right.

289
00:21:37,190 --> 00:21:42,710
So if you just hover over it you say it gets the total number of elements in the dam in all the dimensions

290
00:21:42,740 --> 00:21:43,970
of the tree.

291
00:21:43,970 --> 00:21:44,360
All right.

292
00:21:44,540 --> 00:21:52,460
So you get the length of the entire area and then you run from 0 0 1 to the counter is less than the

293
00:21:52,460 --> 00:21:53,410
length of the area.

294
00:21:53,420 --> 00:21:59,360
And so lengthier arcs the same way as well if we had defined the size.

295
00:21:59,360 --> 00:22:05,090
So because we didn't define a size nor regardless of the number of eyes you put there to find out how

296
00:22:05,090 --> 00:22:07,710
many are there you just see that length.

297
00:22:07,850 --> 00:22:08,220
All right.

298
00:22:08,600 --> 00:22:14,060
But once again the weakness here is that I had to predefined these values and that is not necessarily

299
00:22:14,060 --> 00:22:15,590
the best way to do it.

300
00:22:15,590 --> 00:22:21,430
So we have another bit at time and it's called a list or another collection type.

301
00:22:21,680 --> 00:22:22,960
And it's called the list.

302
00:22:23,000 --> 00:22:26,460
So firstly we're going to declare a list.

303
00:22:26,480 --> 00:22:31,600
So at least declaration is very similar except there are no square brackets so it's a list.

304
00:22:32,900 --> 00:22:42,260
And then let's say that I want a list of strings so this time I want to be storing the names of the

305
00:22:42,260 --> 00:22:47,420
students in the school so I can see a list and then the data type which is string.

306
00:22:47,420 --> 00:22:48,260
All right.

307
00:22:48,260 --> 00:22:49,890
And then give it the name.

308
00:22:49,890 --> 00:22:52,010
So list names.

309
00:22:52,010 --> 00:22:52,220
Right.

310
00:22:52,250 --> 00:23:01,510
So list of type String names is equal to and then we just initialize it the way that we hope list string.

311
00:23:01,610 --> 00:23:07,280
So you'll see in the nuances with the initialization based on the data types and the collection types

312
00:23:07,280 --> 00:23:08,310
that we're dealing with.

313
00:23:08,650 --> 00:23:15,120
But you know as you practice more and more you'll get used to the different four months.

314
00:23:15,140 --> 00:23:17,180
No you'll notice that I have a red line here.

315
00:23:17,180 --> 00:23:24,020
So I have to include another library so by hovering clicking the light bulb I will get system up collections

316
00:23:24,200 --> 00:23:24,890
generic.

317
00:23:25,130 --> 00:23:30,260
So when I click that you will include it and then we can use the list data type.

318
00:23:30,680 --> 00:23:31,070
All right.

319
00:23:31,460 --> 00:23:34,970
No to add to the list.

320
00:23:35,240 --> 00:23:42,740
So this is the clearing the list to add values to the list let me just put in the comment add values

321
00:23:42,740 --> 00:23:46,320
to a list in order to do that.

322
00:23:46,330 --> 00:23:51,430
We simply just see names which is the name of the list dot.

323
00:23:51,520 --> 00:23:57,910
And then when we say dots we see that we have a bunch of functions available to us we can find we can

324
00:23:57,970 --> 00:23:59,030
get the count.

325
00:23:59,050 --> 00:24:01,670
So columns would mean that whatever.

326
00:24:01,700 --> 00:24:02,770
It's just that length.

327
00:24:02,770 --> 00:24:04,610
So Collins does the same thing as a name.

328
00:24:04,630 --> 00:24:09,270
Because as you can see I don't know how many values will be in the list.

329
00:24:09,280 --> 00:24:12,690
So the list is also a variable size we don't know.

330
00:24:12,700 --> 00:24:14,830
It could be one it could be a few it could be none.

331
00:24:14,830 --> 00:24:15,100
Right.

332
00:24:15,430 --> 00:24:16,870
So columns will tell us that.

333
00:24:17,020 --> 00:24:23,340
But to add something we simply do the name of the list which is names not hard.

334
00:24:23,340 --> 00:24:24,160
All right.

335
00:24:24,160 --> 00:24:31,090
And then when we open the braces we see that it's a function that is expecting a parameter of the data

336
00:24:31,150 --> 00:24:34,540
type that the list is representing.

337
00:24:34,540 --> 00:24:36,850
So the list is off type string.

338
00:24:36,850 --> 00:24:40,390
So it is expecting string some string value.

339
00:24:40,420 --> 00:24:48,310
So I can just hardwood a string there if I want so I can see name and I put my name as the first one.

340
00:24:48,340 --> 00:24:48,760
All right.

341
00:24:48,940 --> 00:24:58,040
But then in the and we we can actually do a loop that will allow us to add something from the console.

342
00:24:58,060 --> 00:25:03,760
Now in this situation because it is not counter controlled control or we don't know how many we want

343
00:25:03,760 --> 00:25:09,530
to add or not I wouldn't want to use a for loop because a for loop goes up to a limit at any point.

344
00:25:09,880 --> 00:25:19,630
So I could use a while loop and so what I will do is say something like define a variable called name

345
00:25:19,750 --> 00:25:21,460
and initialize it to a blank string.

346
00:25:21,460 --> 00:25:25,030
So I add some variables up here that I was using for something else.

347
00:25:25,030 --> 00:25:28,510
You can ignore them in case you're concerned about what they were for.

348
00:25:28,510 --> 00:25:31,530
That's fine to remove them so that they don't confuse you.

349
00:25:31,870 --> 00:25:35,460
But right now I'm just going to define a variable called names.

350
00:25:35,470 --> 00:25:41,320
So the purpose of name is to store the value that the user is going to enter into the console.

351
00:25:41,320 --> 00:25:42,410
All right.

352
00:25:42,760 --> 00:25:47,550
I'm going to set the escape character to be like negative one.

353
00:25:47,560 --> 00:25:47,830
All right.

354
00:25:47,830 --> 00:25:56,650
So that means I'm going to use a while loop to see while the value of name is not our name and I want

355
00:25:56,640 --> 00:26:01,900
to use up some string manipulation and also name as a string so if I as a name dot I can get a bunch

356
00:26:01,900 --> 00:26:03,270
of things about it.

357
00:26:03,380 --> 00:26:03,910
Right.

358
00:26:03,970 --> 00:26:13,780
So I can see if name dot equals and then I'm just going to give it the value so I want to see if name

359
00:26:13,780 --> 00:26:15,300
that equals negative one.

360
00:26:15,300 --> 00:26:19,840
Meaning if the value in name equals negative one.

361
00:26:20,470 --> 00:26:20,800
Sorry.

362
00:26:20,800 --> 00:26:23,100
While it is not equal to one.

363
00:26:23,130 --> 00:26:25,070
So then we just do that.

364
00:26:25,090 --> 00:26:26,440
All right so this is a boolean right.

365
00:26:26,470 --> 00:26:34,600
So this is going to say is name equal to the value negative one that I'm seeing while that is not true.

366
00:26:34,780 --> 00:26:37,950
Then I want to continue the execution.

367
00:26:37,960 --> 00:26:38,220
Right.

368
00:26:38,230 --> 00:26:45,550
So let me just put my prompt and just borrow this code set of writing it all out and I'm just going

369
00:26:45,550 --> 00:26:48,970
to say enter names.

370
00:26:48,970 --> 00:26:59,730
All right and then below I'm going to say name is equal to console dots.

371
00:26:59,850 --> 00:27:02,090
Read the line right.

372
00:27:02,110 --> 00:27:09,540
Some are allowing the user to enter a name into the console volume into the console and the damn street

373
00:27:09,540 --> 00:27:10,530
in the name variable.

374
00:27:10,540 --> 00:27:11,340
Right.

375
00:27:11,370 --> 00:27:18,390
And then I'm going to see if an image actually copy this logic so this is called nesting No.

376
00:27:18,420 --> 00:27:24,010
This is where you have one control structure housing another one so you have a loop which is the while

377
00:27:24,010 --> 00:27:28,110
loop brain of a new statement inside the loops they have missed it and your statement inside a while

378
00:27:28,110 --> 00:27:33,380
loop and if statements and while loops act on conditions some would use the same condition right.

379
00:27:33,720 --> 00:27:42,630
So if name is not equal to the value of negative one then I want to add the value that was injured to

380
00:27:42,770 --> 00:27:44,320
the list stuff names.

381
00:27:44,340 --> 00:27:51,180
Right so we've added one name so far so this one is just going to be hardcoded but then dynamically

382
00:27:51,510 --> 00:27:53,340
I want to see that names.

383
00:27:53,640 --> 00:27:55,720
Which is my list not add.

384
00:27:56,130 --> 00:28:03,590
And then the value I'm passing in is the string value that was entered into the name variable.

385
00:28:03,590 --> 00:28:04,200
All right.

386
00:28:04,380 --> 00:28:08,880
So he's going to do that while name is not equal to a negative one.

387
00:28:08,880 --> 00:28:15,360
So that means on the first or end if I enter Emily then it's this is going to evolve into false or true

388
00:28:15,360 --> 00:28:17,400
or other so we add Emily.

389
00:28:17,400 --> 00:28:23,460
Then afterwards if I say negative one then it will skip over this and then it will come back and realize

390
00:28:23,460 --> 00:28:27,050
it does violated the condition and then it's all right.

391
00:28:27,450 --> 00:28:34,860
And then the same way that we could print values in the ivory is the same way that we can print values

392
00:28:34,920 --> 00:28:40,880
in the lists so they're actually quite a few ways one would be using a for loop.

393
00:28:40,940 --> 00:28:46,320
Right so we would see names not honed instead.

394
00:28:46,440 --> 00:28:51,510
So I'm seeing that and the middle standard salt because I'm just borrowing code so I just want to make

395
00:28:51,510 --> 00:28:52,790
sure I'm consistent.

396
00:28:52,860 --> 00:29:00,270
So the students student names you entered are and then for I.

397
00:29:00,510 --> 00:29:04,470
So this seems subscript rules apply to lists right.

398
00:29:04,710 --> 00:29:10,720
So I can actually see names and then call it by its exact index.

399
00:29:10,740 --> 00:29:16,320
So when something goes into the list it has an index just like it would have had in the RV.

400
00:29:16,410 --> 00:29:16,790
All right.

401
00:29:17,070 --> 00:29:24,210
So I can use a for loop to go through each index for the cones are the size of the list or the number

402
00:29:24,210 --> 00:29:31,000
of items in the list and then it would just I to read through that there is also another we call out

403
00:29:31,040 --> 00:29:32,370
for each.

404
00:29:32,460 --> 00:29:32,790
Right.

405
00:29:32,790 --> 00:29:37,940
So this is probably what you see more often than not where you see it for each.

406
00:29:38,310 --> 00:29:44,820
And then what you're seeing this is I want each item in the least start each item in the collection.

407
00:29:45,150 --> 00:29:49,650
So what I would say something like each item is expected to be a string.

408
00:29:49,680 --> 00:29:56,760
So I have to be clear the item as the data type that I'm expecting for from the string.

409
00:29:56,760 --> 00:29:57,440
Right.

410
00:29:57,480 --> 00:30:00,660
If I'm not so sure I can actually use my keyword via here.

411
00:30:00,660 --> 00:30:06,930
So I've been skirting around using var and that's fine but you can't use var or you can use the strong

412
00:30:06,930 --> 00:30:07,410
type.

413
00:30:07,410 --> 00:30:08,630
That's no problem.

414
00:30:08,640 --> 00:30:12,250
So in this case I use a strong type just to drive the point home.

415
00:30:12,390 --> 00:30:17,580
But I'm saying for each string and then I'm calling it.

416
00:30:17,580 --> 00:30:25,290
Item writes for each string item in the list on the list here is called names.

417
00:30:25,290 --> 00:30:26,090
Right.

418
00:30:26,100 --> 00:30:33,210
So for each one of them I want to cancel I mean a copy that one in my right still console on the right

419
00:30:33,540 --> 00:30:38,820
line and then I would print the item.

420
00:30:38,830 --> 00:30:39,190
Right.

421
00:30:39,450 --> 00:30:44,520
So what happens with this loop is that each time it goes through it will take whatever is inside of

422
00:30:44,520 --> 00:30:49,920
names storage an item and then you would be able to print it to the screen.

423
00:30:49,920 --> 00:30:56,880
And then when it runs out of all of the items inside it just exits the loop by itself.

424
00:30:56,880 --> 00:30:57,210
All right.

425
00:30:57,510 --> 00:31:03,190
So this one is using the for loop.

426
00:31:03,390 --> 00:31:04,590
All right.

427
00:31:04,620 --> 00:31:08,370
This one is using the for each loop

428
00:31:11,690 --> 00:31:12,120
all right.

429
00:31:12,240 --> 00:31:16,520
So that's the difference between lists and variables so when you try to.

430
00:31:16,560 --> 00:31:19,600
But then I mean sort of lists and areas.

431
00:31:19,680 --> 00:31:25,090
So if you try to have a dynamic area it might not work code's best based on its nature.

432
00:31:25,230 --> 00:31:26,910
It's very strict like I said before.

433
00:31:27,210 --> 00:31:34,560
But then when you have a need for a dynamic collection you can always call on the list and then you

434
00:31:34,560 --> 00:31:36,630
have all the data types you have.

435
00:31:36,650 --> 00:31:37,950
Numerical.

436
00:31:38,190 --> 00:31:43,490
You have a query ably of I collection I observable you have a bunch of them.

437
00:31:43,590 --> 00:31:49,770
And the reality is that if you want complex data types like a class go we looked at classes and objects.

438
00:31:49,770 --> 00:31:56,040
If you add a class that you needed to store the list of objects of that class then you could use the

439
00:31:56,040 --> 00:31:58,310
list all right.

440
00:31:58,310 --> 00:32:04,430
So I just added some comments just to notice what each block of code is doing know what we're going

441
00:32:04,430 --> 00:32:08,870
to do is run and then we run through each and every one of them.

442
00:32:08,870 --> 00:32:12,810
So the dynamic Ari the FT story and the list.

443
00:32:13,630 --> 00:32:18,170
All right so we're starting off with our fixed three or five grades so we know that this is only going

444
00:32:18,170 --> 00:32:21,970
to run for five data.

445
00:32:22,160 --> 00:32:25,060
Oh so the pricing space I'm not enter.

446
00:32:25,100 --> 00:32:25,370
Right.

447
00:32:25,370 --> 00:32:32,350
So that would also be a problem of price space or putting some other stream that is not you know can't

448
00:32:32,360 --> 00:32:35,380
be deciphered as a number then it will cause a problem.

449
00:32:35,410 --> 00:32:36,250
But we know the this.

450
00:32:36,290 --> 00:32:36,590
Right.

451
00:32:37,010 --> 00:32:40,880
So just putting in five grades and then it shows you that.

452
00:32:40,900 --> 00:32:41,730
Okay.

453
00:32:41,810 --> 00:32:47,930
The five grade the grades you entered are and the grades you entered are and okay I'm seeing an error

454
00:32:47,930 --> 00:32:54,330
here where it is seeing that I have an index all top bones erode.

455
00:32:54,350 --> 00:33:00,860
So let me stop this and see exactly what went wrong.

456
00:33:00,860 --> 00:33:01,190
All right.

457
00:33:01,580 --> 00:33:02,060
So

458
00:33:05,600 --> 00:33:06,950
I see my mistake.

459
00:33:06,950 --> 00:33:14,040
So I was reprinting grades so what happened is that I have the length of grades one for the for loop

460
00:33:14,120 --> 00:33:17,810
but then I didn't change this from grades degrees one.

461
00:33:17,840 --> 00:33:19,940
So that's my mistake.

462
00:33:19,940 --> 00:33:24,270
If you hit that arrow I apologize it's grades 1 for that area.

463
00:33:24,270 --> 00:33:26,000
All right so let's try that again.

464
00:33:27,890 --> 00:33:28,210
All right.

465
00:33:28,230 --> 00:33:33,770
So we proceed to enter our five grades.

466
00:33:33,860 --> 00:33:34,670
All right.

467
00:33:34,670 --> 00:33:38,630
So here we see we print reprinted our five grades.

468
00:33:38,630 --> 00:33:39,620
That's good.

469
00:33:39,620 --> 00:33:44,570
And then we printed Oh it's the ten grades from the dynamic I read right.

470
00:33:44,630 --> 00:33:49,580
And then it meets the province where it's asking us to enter names.

471
00:33:49,580 --> 00:33:53,200
All right someone to enter a name I did it.

472
00:33:53,230 --> 00:34:02,660
Emily went to see Red John and Henry and want more Denise.

473
00:34:02,680 --> 00:34:03,340
All right.

474
00:34:03,380 --> 00:34:09,140
When I press enter and write negative one as my value then it exits the loop.

475
00:34:09,260 --> 00:34:09,590
Right.

476
00:34:09,590 --> 00:34:10,880
So negative one.

477
00:34:10,920 --> 00:34:17,330
It was the exit character and here were reprinting all of the names in the list so remember Tibor we

478
00:34:17,330 --> 00:34:19,220
added that one manually.

479
00:34:19,220 --> 00:34:20,000
Right.

480
00:34:20,060 --> 00:34:22,940
But then all the others we entered as we went along.

481
00:34:22,940 --> 00:34:27,290
And then this is with the for each loop and you can see that the results are pretty much the same.

482
00:34:27,380 --> 00:34:32,180
But for me the syntax for the for each is just much easier to write.

483
00:34:32,180 --> 00:34:36,800
All right so that's basically it with with the lists and collections.

484
00:34:36,800 --> 00:34:40,260
That's a broad idea when you get more advanced.

485
00:34:40,250 --> 00:34:47,820
You see that you can actually use collections and more so lists with bigger data types more complexity

486
00:34:47,820 --> 00:34:48,710
of the types.

487
00:34:48,710 --> 00:34:53,540
I don't want overwhelm me in this lesson but as you go along you will get more advanced.
