 Hey everyone, this is Brian. Welcome to the 12th C-sharp tutorial. Go ahead and create a console application. Alright, now, so far if you've been following my tutorials, we've discussed, you know, variables, the if statement switch, do loop, for loop, for each array, lists, and hash tables. We could go on and on with like stacks and queues and things of that nature, but you know, I honestly believe that programming is easy. And in order to learn programming, you're going to learn by doing. So we're just going to jump right in with both feet. No nonsense. We're going to cover classes. So right click in your solution, go add and select class. And I believe you can also go project add class. And then just from the window that appears, select class. Notice how there's a bunch of stuff in here. Once we get going with these tutorials, you're going to know what each one of these items are. So here's a class. Now you notice how it created a new file, class 1.cs. You can click this tab and there's program.cs. The .cs stands obviously for C sharp. And over here you see here's our class 1 and our program. Now program, this is what we're used to seeing. Name, space, console, application 1, class, program, static void main. When you flip into class 1, you notice how there's no main function. See, program, there's static void main. Class 1, no main. Why is that? Well, as I've said in previous tutorials, the static void main function, or just the main function, that's the starting point for every program. So you only need one of those because it's, well, only going to start in one place. So what is a class and why do you need it? If you know other languages, you're probably snickering going, come on, I know what a class is. But it's important to note that in.net everything is an object. So everything's a class because a class is a blueprint for an object. Let's just write that out, blueprint. So our class is a design of an object. It's not an actual object, it's just what's going to be in that object. So instead of class 1, let's call this person. Save it and we can actually just rename this file if we want to. Don't have to, but you can. Now that we've got this person class, and notice how it's in the same namespace console application 1. Same namespace. Member, a namespace is like an apartment. Because these are in the same apartment, they can chit chat with each other. And no, chit chat's not really a technical term, but you know what I mean. Now we're just going to make a couple of variables here, like, for example, string name. We'll say string.empty. You could have variable just said quote unquote, but just for the sake of argument, I'm going to do string.empty just to show you that the string class is actually a class. And then int age. So this is our blueprint, our class, for an object. We have not created an object yet. So let's jump back into program.cs, and we want to actually work with this. So we're just going to say console.read. That way, you know, we have our console window that stays open. Now, if you type in person, notice how IntelliSense automatically pops up and puts it in the correct upper or lower case, however you have it spelled. Because remember, case sensitive in C sharp. Go ahead and hit tab. There's person. So we've created a variable here, or I should say we've created a type. Now we're going to create a variable, C person. Equal new person. Now we've actually created an object. Remember, the person is just a blueprint. Here's our variable. We're creating a new instance of that blueprint. Thus, we're creating an object. That's very important to note, because some people get class and objects mixed up. And you'll hear it all the time, especially if you work in a programming shop. Some of the newer programmers go, yeah, I was running my class. No, you were running your object. Your class is a blueprint. So now that we've got our blueprint and we've created an object, what can we do with it? Well, whatever we pretty much said. Now you notice how when you do person. There's nothing there. I mean, at least not the stuff we added. There's equals get hash code, get type and two string. Well, because everything's an object, it automatically inherits the properties of an object. So it gets equals get hash code, get type and two string. But what happened to name and age? Well, we need to make these public. That's called an access modifier. By default, the access is private, meaning only this class, only this blueprint, can access these items. So if we make name public, just by putting the public keyword in front of this, and let's leave age the way it is. Go back here, press dot again. You notice how we can see name now, but we can't see age because age is still private. It's the same thing as writing private in front of it. And some people, myself included, will actually put the word private in front of the variable just to make it more clear that you intentionally want this to be private. It's a good way to hammer out bugs in your program. So you go back here, say, still name. So what we want to do is just flip this over to public, go back here, press dot again. You notice how magically there's age. Name and age. So we can say age equals, and we're just going to say, whoops, we'll say 36 because, well, I'm 36, and we'll say see person, name, equal, and just, you know, enter your name. Whoops, got to enter in the quotes. That'd be a good idea to do that. So now we have our object. We are manipulating variables within that object. So we can run this after we actually do a little bit of, we'll just say right line, let's say see person, that name, let's say see person, age, and let's just say, let's put the word years in here, make it a little more friendly, press F5 to run, and it says, Brian is 36 years old. Now, what we're doing is called object-oriented programming. It's called object-oriented because, well, you work with objects. So we're going to create a blueprint. We turn it into an object by creating an instance of that blueprint, our class. So let's actually make another one of these. Let's just call it see person two. Not a very friendly name, but, well, you get the drift here. And then let's just, I'm a big fan of copy and paste. If you've watched my other videos, you know that. So let's just do a little magic here. Now we've got two instances of our class. See person and see person two. Both the same class, both of the person class, but there's two different instances of it. And that'll become very clear when we do this. Let's say console, right line. And let's do see person two and see person two. So we're going to print out the values of the name and age for see person and see person two. And you'll see that although they're the same class, they hold different properties. Brian is 36 years old, Heather is 18 years old. So that is the power of object-oriented programming. You can make a blueprint. And inside that blueprint, you can control what the object does. And it gets much more complex than this. We're going to cover all these in the next tutorials. For example, functions. You can create blocks of code that do certain things. But I just wanted to introduce you to the concept of a class and a blueprint. If this is new to you, don't get overwhelmed. Think of it as a blueprint. You're quite literally drawing a blueprint for an object. An object is just a thing. Then you create an instance of that blueprint when you say new and then whatever the blueprint name is. And these parentheses is a constructor, meaning you're constructing the object. Well, that's all for this tutorial. I hope you found this educational and entertaining. And thank you for watching.