This is our second and final lecture in module nine. As a reminder here that our learning objective through the module. So last time, we talked about arrays as a way to store multiple game entities, if you will, elements that we could then process in a reasonable way. And it saved on how many variables we needed. And we saw how it could save us some code and so on. Arrays are a structure that tends to be available in pretty much every modern programming language. Though in most of them, as in c sharp, we need to know how many elements of array we need when we create the array object. In some cases, that works just fine. But in cases where the size of, excuse me, the number of the elements we need to store can change dynamically. For example, in a game where we're actually spawning stuff, and killing stuff off, and so on. That's a problematic limitation So this time we're going to look at something called collection classes that don't have that limitation. They can dynamically grow and shrink as we need them to as the game runs. You should immediately take an in-lecture quiz to tell me what you know about what collection classes can hold. And this slide should look really familiar to you because I basically came in and replaced the word arrays with collection classes. So, just as with arrays, we can store anything. But. Same as with arrays. A particular collection, which is an object just like arrays are. A particular collection can only store a single data type, and we can have lots of different collections that store lots of different stuff, but we can't mix data types in a particular collection. So, the next question is where can we find these things? And for that, we should open up the IDE and look at Help. So, here is the project that we used last time with arrays. This was our final product from last time. And I'm going to convert it to use a particular collection class. But, before I do, I want to go to Help. And show you where you can find all the collection classes. So, this is a name state, a name space, system dot collections dot generic. And we'll talk about generic again momentarily. But I'm going to click on the very first search result. And you can see here that there are a whole bunch of different collection classes we can use. And as you go through your programming career, you will discover that some of these are more effective in particular situations than others. But for us, for right now. We're going to go and use the list collection class, this one right here. But when you're going to look for collection classes, you should go to the systems dot collections dot generic namespace. [INAUDIBLE] . In the interest of full disclosure I should tell you can also go to the systems dot collections names space, but the generic collections tend to be the ones that are most useful. And, and better programnming practice in general. So here we are. And what I want to do is I want to convert this from a array, from an array into a list instead. So what I'm going to do is I'll just comment this up. The first thing we need is a data type, and the data type is list as we saw. However, it's actually a generic so we have to say a list of what, just as we had to say an array of what when we were declaring an array. Here we have to say a list of what? And let's make it Texture2D, because that's what we want to store. Now, you should be, hopefully, thinking you've seen something like this before. When we use the Content Manager Load method, I said this is an instance of a generic, and we had to, between the less than and greater than signs, we had to put the data type. Of the content that we need it to load. And that, the load method is actually a, what's called a generic method. Whereas this list class, is a generic class, but the idea is the same. We have to put the data type that we want to store. In between the less than and greater than. So you've seen this before, when we loaded content. This is in a slightly different context. It's basically saying the data type of the elements we're going to store in the list. So I can still call it characters, and it's still an object, and in fact it's a list of texture 2Ds So I have now created this new list, the only other thing I need to change in this code is to convert from arrays to list, is right here where I was setting these particular, where I was loading the elements of the array, because with the list class, we don't actually do it this way. We add things to the list. So instead of saying characters zero equal content load that Texture2D, I'm going to say characters.Add, like that. And what happens is it will load this Texture2D, the content manager still loads this content as it did before and it will add this to the begin, sorry, it will add it to the end of the list. And since this is an empty list, it will add it at the zero location. And so, to add each of these to the list, we just change the syntax. Like this. And this will work to add character zero at location zero in the list, character one at location one in the list, character two at location two in the list, and character three at location three in the list. And when I run this. It works exactly the way it did before, except now we're using a collection that we dynamically grouped as we went along. So, that's it for the conversion of the code to a collection. What that means Is I have a couple of in-lecture quizzes for you. So, do this first one that really gets at the key difference between collection classes and arrays. And, now do this one which addresses something that I haven't even spoken about at all today. So the answer to that is, we access elements of the list just like we accessed elements of the array. We use the sqaure bracket notation to get at stuff in the list. Now, it might be hard to see from this example why collection classes are useful. Right? Cause Sure I changed some syntax here, but we really didn't see any huge benefit. Next module, we will see why this is really useful. We need one more piece of understanding about how c sharp works before we can see why collection classes are so much more powerful then arrays for, for games in general. So we'll have to wait patiently. But we did see that collection classes can also be used to store multiple elements for ease of processing, just as we used arrays for. We learned that collection classes can grow and shrink dynamically, which is something that arrays can't do. And then next time, we'll start on the next module where we'll learn the final control structure we need to be able to solve, sort of, almost any problem you can imagine.