1 00:00:00,680 --> 00:00:01,430 ‫We'll come back. 2 00:00:01,460 --> 00:00:06,800 ‫In this video, we are going to have a look at some theory of arrays in C sharp and the next video. 3 00:00:06,800 --> 00:00:09,980 ‫We're going to see it in practice and we're going to see a demo. 4 00:00:09,980 --> 00:00:16,130 ‫So let's get started first with the theory behind it, because it's quite important to understand what 5 00:00:16,130 --> 00:00:19,760 ‫the general idea of a race is and how we can use them. 6 00:00:19,760 --> 00:00:28,580 ‫So an array stores a fixed size sequential collection of elements of the same type, so it stores a 7 00:00:28,580 --> 00:00:29,480 ‫fixed size. 8 00:00:29,480 --> 00:00:34,160 ‫And the important thing is it's only of the same type. 9 00:00:34,160 --> 00:00:41,720 ‫So you can store multiple information within one variable, so to say, but it has to be the same type, 10 00:00:41,720 --> 00:00:43,790 ‫so it cannot be in one spot. 11 00:00:43,790 --> 00:00:46,430 ‫You have a string in another, you have an integer and so forth. 12 00:00:46,430 --> 00:00:48,140 ‫It all has to be the same type. 13 00:00:48,860 --> 00:00:56,210 ‫Then you can create arrays of all different kinds of types, so you can create an array which only contains 14 00:00:56,210 --> 00:00:56,750 ‫integers. 15 00:00:56,750 --> 00:01:01,250 ‫Then you can create one which only contains strings, objects and so forth. 16 00:01:01,250 --> 00:01:06,980 ‫So pretty much everything can be stored in an array, but it has always to be the same type for that 17 00:01:06,980 --> 00:01:07,970 ‫specific array. 18 00:01:08,000 --> 00:01:11,450 ‫Then it's really great to store a collection of data. 19 00:01:11,450 --> 00:01:18,980 ‫It's easier to think of as a collection of variables of the same type stored at continuous memory locations. 20 00:01:18,980 --> 00:01:24,500 ‫So simply imagine it like some storage that you have and you can put information in it. 21 00:01:24,500 --> 00:01:26,840 ‫So this is a structure of an array. 22 00:01:26,870 --> 00:01:30,080 ‫In this case, it's an array with a length of six. 23 00:01:30,200 --> 00:01:34,010 ‫So there are six values within that array. 24 00:01:34,010 --> 00:01:37,400 ‫And in this case all of them are integers. 25 00:01:37,400 --> 00:01:40,700 ‫So you have the number 13, 15, five and so forth. 26 00:01:40,700 --> 00:01:46,340 ‫So these are different memory locations, but they are all within the same array and that allows us 27 00:01:46,340 --> 00:01:51,500 ‫to store multiple information in one variable so we don't have to create ten different variables or 28 00:01:51,500 --> 00:01:57,020 ‫50 different variables, but we can create one array which contains all of those information and we 29 00:01:57,020 --> 00:01:58,880 ‫can access them later on. 30 00:01:58,880 --> 00:02:02,120 ‫And what's important here is that we have indexes. 31 00:02:02,120 --> 00:02:07,820 ‫So in order to store something in an array, we need to store it at a specific index. 32 00:02:07,820 --> 00:02:16,640 ‫So for example, the 13 is at the index of zero, then 15 is the index of one and this order is always 33 00:02:16,640 --> 00:02:17,120 ‫maintained. 34 00:02:17,120 --> 00:02:20,360 ‫So it always starts at zero and it always goes up by one. 35 00:02:20,360 --> 00:02:24,680 ‫So in this specific array, the element and index four has a value of eight. 36 00:02:24,680 --> 00:02:26,330 ‫So this one here. 37 00:02:27,020 --> 00:02:30,200 ‫Is indexed for and the value is eight. 38 00:02:30,740 --> 00:02:35,270 ‫Now, in order to declare an array, you need to specify the data type. 39 00:02:35,270 --> 00:02:41,120 ‫Then you have the square brackets and the array name, for example, int grades. 40 00:02:41,120 --> 00:02:44,060 ‫So you can see here this is an array of grades. 41 00:02:44,060 --> 00:02:47,830 ‫So the students get grades and this is an example of a grades. 42 00:02:47,840 --> 00:02:50,870 ‫You could store all the different grades for your students. 43 00:02:50,870 --> 00:02:55,520 ‫Then in order to initialize an array, you have to go the following way. 44 00:02:55,550 --> 00:03:01,670 ‫You create the array with data, type again, then the square brackets the array name, then you need 45 00:03:01,670 --> 00:03:09,020 ‫to keyword new and afterwards you have the data type again and in square brackets the amount of entries 46 00:03:09,020 --> 00:03:10,850 ‫that this array should have. 47 00:03:10,850 --> 00:03:16,880 ‫So in the case below you have the grades which contains five grades. 48 00:03:16,880 --> 00:03:21,920 ‫So five whole numbers of type integer are within that array called grades. 49 00:03:22,100 --> 00:03:26,330 ‫Then in order to assign values to an array, you simply use the array name. 50 00:03:26,330 --> 00:03:32,330 ‫Then in square square brackets you enter the index as we've seen earlier, and then you add the value 51 00:03:32,330 --> 00:03:33,410 ‫after the equals sign. 52 00:03:33,410 --> 00:03:35,990 ‫So here grades at the position zero. 53 00:03:35,990 --> 00:03:42,620 ‫So at the index zero is 15 grades at the position or index one is 12. 54 00:03:42,920 --> 00:03:44,990 ‫So that's just some examples. 55 00:03:44,990 --> 00:03:49,850 ‫So here, going back to the structure of an array, you can see the array name at position four. 56 00:03:49,850 --> 00:03:52,850 ‫That's how you would get it has the value of eight. 57 00:03:53,600 --> 00:03:55,730 ‫So that's the basis of a race. 58 00:03:55,730 --> 00:03:58,130 ‫And we're going to see a lot more about a race. 59 00:03:58,130 --> 00:04:03,110 ‫There is a lot more to know about the race, but most of the things make much more sense when you do 60 00:04:03,110 --> 00:04:03,860 ‫them in practice. 61 00:04:03,860 --> 00:04:06,740 ‫So we're going to have some demo videos following. 62 00:04:06,770 --> 00:04:08,120 ‫See you there and have fun.