 Everybody, this is Brian, and this is Visual Basic 14. If you're following along, you've already learned to raise, today we're going to learn lists and generics. So let's dive right in, create a new variable called people as list, and you notice there's a list of t. What does of t mean? List means of type. So we have to give it a type. In this case, we're going to say string. Now we declared our variable, but we haven't initialized it. What do I mean by that? Well, if we try to say people.add, and we try to add bop to the list, Visual Basic's going to throw an error and say, look, you're trying to use this variable before it's been assigned, and all reference exception will occur. In plain English, what that means is you haven't assigned the variable, so it doesn't exist. You've said I plan on using a variable named people, but you haven't actually made the variable. Confusing, I know. Say new, whoops. Let's get rid of that list of, and we've got to give it the same type, string. So here, we're declaring it. Dim people as list of string. Here, we're initializing it. People equal new list of string. And yes, you can do this all in one line. So you're declaring and initializing all in one line. I like to do it that way. That way, you don't forget to initialize it and have nasty errors later. Notice how we can now add bop to the list. Let's just add a few people here. We'll say Mary and Chad. So why do we need a list? We already have arrays. Well, lists are much more flexible and much more convenient, as you can see. Everything is an object in .NET, and that's what you're going to really be focusing on in this tutorial. Dim, we'll say sname as string for each sname in people. And then we can just console, write line, and we'll just print out the name. Now what do I mean by everything's an object? Remember, I've said that once before in an earlier tutorial, and I never really explained it in depth. Well, people is an object. That object is a list. You're creating an instance of that list. Once that instance is created by saying equal new list of string, you can call its methods and get its properties. For example, when you hit people and then ., you get a list of properties and methods. There's a lot of them. You can do a lot with a list. It's very powerful. You can union. You can search. You can sort. You can find. You can remove individual items. And you don't have to do a redim preserve. It's much more flexible. Now gaining that flexibility, you lose speed. I'm going to show you just a couple simple examples of what this class can do for you. And this is called a class. We'll get into classes in another tutorial. Just know that it is a class. Remember, a class is a blue print. And once you initialize it, it's an object. So let's run this. Sure enough, there's Bob, Mary, and Chad, and less. Well, let's say we want these sorted. Well, we can say people.sort. So rather than having to make some nasty little algorithm to do our work for us, the list class is actually sorting it for us. It's very convenient. You see now that our list is sorted, we have Bob, Chad, Mary. Now you can also say, let's say we want to get rid of Bob. We don't like Bob. So we're going to say if people.contains. And we're looking for Bob then. And the contains method, or actually function in Visual Basic, will return a boolean, meaning it returns true or false. So if it finds Bob, it's going to say true. We're going to say people.remove. And we'll say Bob. So if people contains Bob, remove Bob. Run this again. And there's Chad and Mary. So as you can see, it's much more flexible than an array. You don't have to juggle things around. You don't have to read and preserve. You can add things in the middle. You can tack them onto the end. And you can do all this dynamically without having to recreate the whole thing every single time. For example, let's say people, let's get rid of this. Let's keep Bob, Bob suddenly our friend again. Let's say people insert. And we want to insert. And this is like an array in the sense it's zero-based. So let's say we want to put this in the first position. And we want to add, let's add my daughter, Heather, because she's been good this week. I will add her to my people list. Now this is zero-based. So zero, one, two. Let's run this. So you can see at the first position, which was Mary, we added Heather. But you notice how Mary's at the bottom. Why? Because we're calling people.sort. Now because we're calling people.sort, it rearranges everything. So let's get rid of that. Run this again. Now you can see that Heather is right before Mary. She cut in line. She's been bad this week. I'll have to ground her later for that. Just kidding if you're watching, kiddo. So that is a list. Now let me talk about generics a little bit more. What is a generic? You notice how it says list of string? Well, you're giving it a list of a type. You can put anything in there. And that's what's called a generic. A T, or the shorthand for type, is just generic. Meaning you can throw a string, a bolean, an integer, and this list will work exactly the same. You can still add items. But it has to be of that type. You cannot say people.add and then try to add a zero here. Because you're trying to add an integer. Well, actually, maybe it'll let me do it. Yeah. Visual basics a little more flexible. It'll convert that to a zero. Some other .NET languages won't do that. It'll actually explode and say, whoa, hold on. Now you can't do that. Now if this were a list of integers and you tried adding bob, it would most definitely explode and tell you, you know, you're stupid. Check your code compile and all this other nonsense. And basically, just stick with a certain type. Don't try to automatically add things and hope that VB will cast them or convert them the way you want them. So that's been our tutorial for today. I hope you found this educational and entertaining. And thank you for watching.