‫Welcome back.
‫In this video we're going to look at i enumerable one more time and it's another demo where we're going
‫to see how we can pass an ai enumerable to a method as a parameter.
‫And this gives us a lot of flexibility because well, similar to what we have when it comes to inheritance
‫in object oriented programming, where the instance of a child class can be passed the same way the
‫parent would be passed into a method call, for example, as the parameter.
‫Something similar happens when we are working with collections that implement the AI enumerable interface,
‫as we have seen in the last video where we could replace the AI enumerable, so to speak, with lists,
‫with queues as well as with arrays.
‫Okay.
‫So let's go ahead and just create a new method here which will in fact take an AI enumerable collection
‫as the parameter.
‫So I'm going to put that down here.
‫And as you can see, we're using the AI enumerable, which is of course going to require the generic
‫collections namespace up here.
‫All right.
‫Now we can use it throughout our file here.
‫And what I'm going to have is basically a sum that will store the sum of the numbers in any type of
‫collection.
‫So in our any collection.
‫And then we're going to go through each item in the collection and add that together and put it into
‫sum.
‫So basically summing up all of the values that are inside of that collection and then we are just going
‫to write out the result of the console.
‫So console right sum is and then the sum.
‫Okay.
‫So that's the idea behind this collection some.
‫Now, the cool thing is we can pass any type of collection to it that implements the I enumerable interface.
‫That means that we can pass a list, we can pass an array.
‫So we have a bunch of options here.
‫So let's actually make use of that.
‫Therefore, I'm going to set up a list like so in my main method list, number list.
‫So this will just be a list of numbers.
‫Then I'm going to do the same thing with the array.
‫So I'm going to create a number array of integers.
‫Then I have a new line where I'm creating a new line using this right line statement, and I'm going
‫to call my method collection some where I'm going to pass the numbers list, which is this list full
‫of numbers eight, six and two.
‫So if we pass that and then run the program, it will display the result of eight plus six plus two,
‫which is going to be 16.
‫All right.
‫And now the cool thing is we can, of course, do the same thing with our numbers array like so.
‫So here we are passing the number array, which is an entirely different type.
‫Right?
‫So this is not a list, this is an array and we're just passing it in.
‫And if we run it, we will see that it will work the same way.
‫So it's going to say some is 12 and that is the sum of one plus seven plus one plus three.
‫So that's really the advantage of using the generic type I enumerable here.
‫So basically the base type, you could see it's not really the base type of a list, right?
‫But the list class implements the I enumerable.
‫So if you go over to a list here, you see it follows the instructions of the I enumerable of the generic
‫as well as the non generic options here as you can see.
‫And that's really the cool thing here.
‫That's really the power of using I enumerable So yeah, that's it for this video and I hope you have
‫a certain idea of what you can do now with the i enumerable rules.
‫And whenever you come across the I enumerable collection type, you will not be confused because they
‫are used quite a bit in programming.
‫So I hope you enjoyed this video.
‫See you in the next one.