 Everybody, this is Brian. Welcome to the 10th C-Sharp tutorial. I'm just gonna make a console application today We're gonna talk about lists and to do that. We're gonna have to talk about namespaces a little bit now You see this keyword namespace. What does that mean? Well, remember we've kind of talked about this briefly where a namespace is like an apartment and You can only have one person of one name in an apartment Notice how this is console application one. There can only be one console application one apartment and There is a program in the console application one apartment so What this does is it separates things so if you make a class or a blueprint and let's say you make a Class called cat because I like cats and Somebody else makes a class called cat. Well, that's gonna be a name conflict So you have to put them in separate namespaces that way Someone would go to your namespace and use your cat class or their namespace and use their cat class Well, you see all these using these are all namespaces. So you've been using this all along and never known it System, that's the core system of dot net System collections generic. That's something we're gonna be working with today System link. We'll cover that in the future and system dot text that deals with text processing So you're using namespaces Now what we want to do is make a list So if you type in LIST and you notice how it's got these less than and greater than signs And it's got this thing and these and these one. What is all this stuff? Well, these are collections. They're also called generics and just select list with the little brackets and Then if it doesn't pop up type the bracket notice how it says system collections generic list T T is the type of elements in the list Well, give it a type String in this case and then in bracket Now we have to give it a name. This is just a variable. We're making here. So we're gonna say customers equal new And then you have to give it the end brackets at the end there So this looks very complicated, but let's review it list. So we're making a list object The type of things that go in the list is a string. So we're saying this is a list of strings We're calling it customers and Then it's going to be equal new list of strings and then we give it the constructor something We haven't talked about yet. Just kind of click the I believe button So what is a list? Well a list is like an array in the sense that it holds multiple objects you can say Maybe if I could type customers dot add and then you can add a string item that will just say We're gonna add Bob in here then customers dad Mary Dad and I'm just gonna pick a name at random here. We're just gonna say Chad So this looks very similar to what we discussed with the ray. Why would we use a list? I mean, it's got this Funky looking syntax. It's really hard to follow. Why would you use that instead of an array? Well simple lists are much much more powerful an array you hit an upper limit and you stop You can't add any more you'd have to make a bigger array and then copy the items to it with a list You can just keep growing and growing and growing you can also do things like customers dot Insert so you can actually insert something into the list at a specific index. So we're gonna just uh We'll say at the second spot We're going to insert Heather so if you're following along here, this would be zero This would be one Two and then we want to insert at the second spot. So actually right here is where we're gonna add Heather So let's just say for each string customer in customers And we're gonna do a console right line Customer and then of course we want our console read line that way we keep the window open here And let's go ahead and run this and Sure enough we have Bob Mary our inserted item of Heather and Chad That's something you really can't do with an array a razor are kind of old-school very rigid very difficult to work with and to be honest Eraser kind of I want to say they're going the way of the dinosaur, but they'll be around for a long time for legacy reasons But as you can see a list is much much more flexible now The thing about lists is you can also make it with other things This is also kind of a tutorial on generics here Remember when you do list and then you have that T you could have very easily typed int for integer and we'll say I don't know. Let's just call this ages Equal new and then you could say oops ages dot add And you could just add a 10 and you kind of get the drift here I mean you can just you know to your heart's content you start adding things There's no upper limit no upper bounds You'll just keep going and going and going and because you give it this type You know what type of objects it expects and what type of objects we're going to get back For example when we say for each string customer and customers if we change this to an int Notice how he gets kind of angry at us as well cannot convert type string to int because remember customers is a bunch of strings So it knows hey, we're expecting a string here not in it. Why is that important? well That's important because if you try to get an integer out of a name say Bob Bob is not a number So you're going to crash your program So it does this type checking to make sure that your program is going to be more stable So that in a nutshell is the bare bones basic of lists and generics and remember that is coming out of the system and collections that generic namespace This is Brian. Thank you for watching. I hope you found this tutorial educational and entertaining