 Hey everybody, this is Brian. If you're following along, this is video 20 in our visual basic series. Today we're going to be discussing classes. Before we do that, however, let's discuss modules real quick. Modules, as you see here, this thing you've been playing around with this whole time, is just a file that contains code. A class, on the other hand, is a blueprint for an object. Remember, everything in .NET is an object. To create a class, you go project, add class, and double click class. You see this is public class class 1. It also creates this file called class1.vb. As you see, you double click your module and your module comes up. You double click your class, your class comes up, and you have these handy tabs you can flip back and forth. Now that we have our class, which is appropriately titled class 1, we have to define what this blueprint is going to have in it. You do that by adding variables, functions, and subroutines, all the things that we've covered so far. But you have to do it a little different. You have what's called an access modifier. You have public and private. There's others, but we'll get to them later. So just say public, name as string, and private age as integer. And let's actually change class 1 to person. And over here, right click this and rename class 1 to person.vb. That way you don't get confused. You can see person relates to the person.vb file. Now go back to module one, and we're going to actually create an instance of this. We're going to say, dim my friend as person equal new person. So now we have a variable called my friend, which is a person. We're defining person in our blueprint here. So far, we just have two variables, so public and a private. Now remember, these are access modifiers. And what does that mean? Well, public means you can access from outside of the class. Private means, well, you're going to only access it from inside the class. It's kind of like, you know, you ask a woman, how old are you? And they say, I don't want to tell you, but they know inside. They know. Anyway, so say my friend.name equals, and we'll just say chad. And console.rightline. And we'll just say my friend.name. We're just going to write out the name to the console. Now, this is how when we did my friend dot, we only see name. Even if we flip over to all, well, there's no age. Once again, that's because age is a private variable. It can only be accessed from inside the class. But what are all these other things you're asking? Equals, get ash, code, get type, reference equals to string. You see everything in dot net is an object. These are methods that inherited from the object class. I know that's confusing, but there's actually a class, public class in dot net called public class object. And it defines all these things. And because our class inherits from the object class, we get these things automatically. We'll discuss inheritance in another tutorial. So we're just going to run this. And you see it spits out chad. Now real quickly, because there's a thunderstorm outside, we're going to discuss constructors. Go to your class, go to declarations, and select new. Notice how it says public sub new. And we're just going to go console. Right line new person created. What we're doing is we're making a constructor. The public sub new is called automatically when you create an instance of this class. You see, here's our class person. And when we say equals new person, we're actually creating an instance of this class. It's one thing to have a blueprint. It's another thing to build something from that blueprint. Person, the class person is the blueprint, creating a new instance of that person actually assigns the variable. I know it gets a little confusing. So if you need to rewind it a couple of times and listen to it, when you run this, you see it now says new person created and then chad. Well, what's going on here is we are assigning a variable a new instance of the person class, which is calling this constructor new. See how it says new person created. So it's called automatically when you say the new keyword. One thing you can do is what's called operator overloading. Just type m age as integer and do me dot age equals m age. Now the me is just a reference to the current object. In this case, the person class. So me dot age, in other words, this age is going to get assigned this parameter of m age. And we'll just change new person created to with age. So you can see which constructor is being called here. And when you add a parentheses after new person, you notice you now have no two options. New with no parameters and new with the age parameter. We'll just say 35. So we're going to say chad is 35. Notice how when you look at this public sub new, bival m age as integer. Don't worry about bival for now. Just look at m age as integer. So we're passing an integer and then assigning it to this private age variable. And when we run this, you see new person created with age chad, meaning we've created an instance of this class. Whoops, I accidentally closed that. It's calling this constructor here. And it's assigning the age value. Now, how do you get that age value if you can't access it from outside of your class? Well, that's simple. You make a function or a property, which we'll discover in another tutorial. And just call it get age as integer. And you're just going to return me dot age. So when something outside of your class calls this public function, it's going to return this private variable of age. So we'll do console, right line, my friend dot age, get age. Sorry. Now when you run this, you can see that the new person class is created with the age parameter. His name is Chad. He's 35 years old. So that's all we're going to cover for now because we've got some pretty nasty thunderstorms coming in and I don't want to fry my computer. So I hope you found this tutorial educational and entertaining and stay tuned.