1 00:00:01,080 --> 00:00:01,860 ‫Welcome back. 2 00:00:01,890 --> 00:00:06,930 ‫In this video we're going to look at i enumerable one more time and it's another demo where we're going 3 00:00:06,930 --> 00:00:14,160 ‫to see how we can pass an ai enumerable to a method as a parameter. 4 00:00:14,160 --> 00:00:22,680 ‫And this gives us a lot of flexibility because well, similar to what we have when it comes to inheritance 5 00:00:22,680 --> 00:00:30,660 ‫in object oriented programming, where the instance of a child class can be passed the same way the 6 00:00:30,660 --> 00:00:35,430 ‫parent would be passed into a method call, for example, as the parameter. 7 00:00:35,940 --> 00:00:41,220 ‫Something similar happens when we are working with collections that implement the AI enumerable interface, 8 00:00:41,220 --> 00:00:47,340 ‫as we have seen in the last video where we could replace the AI enumerable, so to speak, with lists, 9 00:00:47,340 --> 00:00:50,610 ‫with queues as well as with arrays. 10 00:00:50,970 --> 00:00:51,110 ‫Okay. 11 00:00:51,210 --> 00:00:59,760 ‫So let's go ahead and just create a new method here which will in fact take an AI enumerable collection 12 00:00:59,760 --> 00:01:01,650 ‫as the parameter. 13 00:01:02,070 --> 00:01:03,960 ‫So I'm going to put that down here. 14 00:01:03,960 --> 00:01:10,740 ‫And as you can see, we're using the AI enumerable, which is of course going to require the generic 15 00:01:11,400 --> 00:01:13,680 ‫collections namespace up here. 16 00:01:14,160 --> 00:01:14,520 ‫All right. 17 00:01:14,520 --> 00:01:17,280 ‫Now we can use it throughout our file here. 18 00:01:17,280 --> 00:01:23,850 ‫And what I'm going to have is basically a sum that will store the sum of the numbers in any type of 19 00:01:23,850 --> 00:01:24,390 ‫collection. 20 00:01:24,390 --> 00:01:26,190 ‫So in our any collection. 21 00:01:26,730 --> 00:01:34,680 ‫And then we're going to go through each item in the collection and add that together and put it into 22 00:01:34,680 --> 00:01:34,980 ‫sum. 23 00:01:34,980 --> 00:01:40,800 ‫So basically summing up all of the values that are inside of that collection and then we are just going 24 00:01:40,800 --> 00:01:44,760 ‫to write out the result of the console. 25 00:01:44,760 --> 00:01:47,550 ‫So console right sum is and then the sum. 26 00:01:48,290 --> 00:01:48,500 ‫Okay. 27 00:01:48,500 --> 00:01:50,990 ‫So that's the idea behind this collection some. 28 00:01:51,080 --> 00:01:59,420 ‫Now, the cool thing is we can pass any type of collection to it that implements the I enumerable interface. 29 00:01:59,540 --> 00:02:03,840 ‫That means that we can pass a list, we can pass an array. 30 00:02:03,860 --> 00:02:05,720 ‫So we have a bunch of options here. 31 00:02:06,230 --> 00:02:08,450 ‫So let's actually make use of that. 32 00:02:08,900 --> 00:02:15,380 ‫Therefore, I'm going to set up a list like so in my main method list, number list. 33 00:02:15,380 --> 00:02:17,300 ‫So this will just be a list of numbers. 34 00:02:17,750 --> 00:02:21,350 ‫Then I'm going to do the same thing with the array. 35 00:02:21,860 --> 00:02:25,280 ‫So I'm going to create a number array of integers. 36 00:02:25,520 --> 00:02:33,020 ‫Then I have a new line where I'm creating a new line using this right line statement, and I'm going 37 00:02:33,020 --> 00:02:39,740 ‫to call my method collection some where I'm going to pass the numbers list, which is this list full 38 00:02:39,740 --> 00:02:41,270 ‫of numbers eight, six and two. 39 00:02:42,200 --> 00:02:50,210 ‫So if we pass that and then run the program, it will display the result of eight plus six plus two, 40 00:02:50,210 --> 00:02:51,950 ‫which is going to be 16. 41 00:02:53,000 --> 00:02:53,570 ‫All right. 42 00:02:53,570 --> 00:03:00,290 ‫And now the cool thing is we can, of course, do the same thing with our numbers array like so. 43 00:03:00,680 --> 00:03:04,610 ‫So here we are passing the number array, which is an entirely different type. 44 00:03:04,610 --> 00:03:04,910 ‫Right? 45 00:03:04,910 --> 00:03:09,580 ‫So this is not a list, this is an array and we're just passing it in. 46 00:03:09,590 --> 00:03:13,610 ‫And if we run it, we will see that it will work the same way. 47 00:03:13,610 --> 00:03:18,650 ‫So it's going to say some is 12 and that is the sum of one plus seven plus one plus three. 48 00:03:19,250 --> 00:03:26,060 ‫So that's really the advantage of using the generic type I enumerable here. 49 00:03:26,060 --> 00:03:30,740 ‫So basically the base type, you could see it's not really the base type of a list, right? 50 00:03:30,740 --> 00:03:33,560 ‫But the list class implements the I enumerable. 51 00:03:33,560 --> 00:03:41,030 ‫So if you go over to a list here, you see it follows the instructions of the I enumerable of the generic 52 00:03:41,030 --> 00:03:44,630 ‫as well as the non generic options here as you can see. 53 00:03:44,720 --> 00:03:47,450 ‫And that's really the cool thing here. 54 00:03:47,570 --> 00:03:53,360 ‫That's really the power of using I enumerable So yeah, that's it for this video and I hope you have 55 00:03:53,360 --> 00:03:57,980 ‫a certain idea of what you can do now with the i enumerable rules. 56 00:03:57,980 --> 00:04:04,430 ‫And whenever you come across the I enumerable collection type, you will not be confused because they 57 00:04:04,430 --> 00:04:06,830 ‫are used quite a bit in programming. 58 00:04:06,830 --> 00:04:08,600 ‫So I hope you enjoyed this video. 59 00:04:08,630 --> 00:04:09,830 ‫See you in the next one.