C# Tutorial - Full Course for Beginners

**Inheritance: A Key Concept in Object-Oriented Programming**

In object-oriented programming, inheritance is a fundamental concept that allows one class to inherit properties and behavior from another class. In this article, we will explore three core concepts of inheritance: inheriting all the functionality from a superclass, extending the inherited functionality, and overriding methods.

**Inheriting All Functionality from a Superclass**

Let's start with the first concept of inheritance: inheriting all the functionality from a superclass. Suppose we have a class called `NormalChef` that has a method to make chicken dishes. We can create another class called `ItalianChef` that inherits all the properties and behavior from `NormalChef`. However, instead of just making chicken dishes, Italian chefs also specialize in making pasta.

In our program, we can achieve this by using inheritance. We define a superclass called `Chef` that has a method to make special dishes. The `ItalianChef` class inherits from the `Chef` class and adds its own specialization for making pasta. When we run the program, both the `NormalChef` and `ItalianChef` classes will be able to print out "Making Special Dish". However, when we use the `ItalianChef` class, it will make pasta instead of chicken dishes.

To achieve this, we need to define a method in the superclass called `makeSpecialDish` that is inherited by the `ItalianChef` class. We also need to specify this method as virtual using the `virtual` keyword. This allows subclasses like `ItalianChef` to override the behavior of the method.

**Extending Inherited Functionality**

The second concept of inheritance is extending the inherited functionality from a superclass. Suppose we have a class called `NormalChef` that has a method to make salads. We can create another class called `ItalianChef` that extends the behavior of the `NormalChef` class by adding its own method to make pasta.

In our program, we can achieve this by using inheritance and extending the inherited functionality from the superclass. We define a superclass called `Chef` that has a method to make salads. The `ItalianChef` class inherits from the `Chef` class and adds its own method to make pasta. When we run the program, both the `NormalChef` and `ItalianChef` classes will be able to print out "Making Special Dish". However, when we use the `ItalianChef` class, it will make pasta instead of salads.

To achieve this, we need to define a new method in the subclass that extends the behavior of the inherited method. We can do this by using the `public void` access modifier and specifying the return type of the method.

**Overriding Methods**

The third concept of inheritance is overriding methods. Suppose we have a class called `NormalChef` that has a method to make special dishes. We can create another class called `ItalianChef` that inherits from the `NormalChef` class but overrides the behavior of the `makeSpecialDish` method.

In our program, we can achieve this by using inheritance and overriding methods. We define a superclass called `Chef` that has a method to make special dishes. The `ItalianChef` class inherits from the `Chef` class and overrides the behavior of the `makeSpecialDish` method by specifying a different return type and implementation.

To override a method, we need to use the `public virtual void` access modifier and specify the virtual keyword on the superclass method. This allows subclasses like `ItalianChef` to override the behavior of the method and provide their own specialization.

By using these three concepts of inheritance – inheriting all functionality from a superclass, extending inherited functionality, and overriding methods – we can create powerful and flexible classes that can be used to model real-world objects and systems.

"WEBVTTKind: captionsLanguage: enHey, welcome to draft Academy. My name isMike in this course, I'm going to teach youguys everything you need to know to get startedusing C sharp, a C sharp is an extremely powerfulprogramming language. And it's used in millionsof applications around the world, there areliterally 1000s of things you can do withC sharp, and there's tons of different applicationsfor this language is extremely powerful. AndI'm excited to be bringing you guys a course,that will teach you everything you need toknow to get started. So we're going to startthe course with the basics, we're going toinstall C sharp, we're going to install atext editor called Visual Studio, we're goingto get everything set up. And we'll startwriting our first program. I'm going to teachguys the basics of programming. So we're goingto look at some of the core programming concepts,things like working with data variables, datatypes, getting input from users, then we'regoing to move on to some more advanced stuff.We'll talk about things like loops, and ifstatements in different data structures. Andfinally, we'll talk about some object orientedprogramming concepts, things like classes,and objects, inheritance, all that fun stuff.If you're new to programming, or you justwant to try and pick up C sharp, then thiscourse has something for you, I'm really excitedto be bringing you guys C sharp tutorials.It's an awesome language, and there are literally1000s of things you can do with it. So withoutfurther ado, let's get started. Let's go intothe course and start learning some C sharp.In this tutorial, I'm going to show you guyshow to install and get everything set up tostart programming in C sharp. Now in orderto start programming in C sharp, we're actuallyjust going to need one thing, which is goingto be a program called Visual Studio community.And this is basically a program that willallow us to write our C sharp programs. Andthis is what's called an integrated developmentenvironment. And then a lot of times you'llhear people call those IDs, it's essentiallyjust a special program where we can writeand work with our code. So in this case, thisis an ID that will allow us to work with theC sharp programming language. So over hereon this website, it's just visual studio.com,forward slash vs forward slash community.And this is the website where we can go todownload this, you'll see over here, there'san option to download on Windows. And thenthere's also an option to download on Macover here. So you can just click whicheverone you need. On my case, I'm on a Windows,so I'm just going to go ahead and click theone for Windows. So click this and that shouldstart downloading and we should get an installerthat we can use to install Visual Studio.So once that's downloaded, I'm just gonnaclick it. And we'll go ahead and run thisinstaller. So when the installer loads up,you'll see that we have this little windowover here. And basically this is a littleprogram that we can use to install what weneed. Now here's the thing, this Visual Studioprogram is huge. And there's tons of stuffthat you can actually do with it. So you cansee there's all these different things wecan install. I mean, there's probably like,over 100 gigabytes worth of stuff that wecan install here, we basically just need thisguy over here says dotnet desktop development,this is all we're going to need, we're goingto be building something called a consoleapplication, which is essentially like thesimplest type of application that we can build.And you'll see over here, it says the installsize is around three gigabytes. So that'sactually not too bad. Some of these thingsare like a couple, you know, maybe like dozengigabytes, something like that. So yeah, clickthis dotnet desktop environment. And I'm justgoing to click install, and we're going togo ahead and install that hopefully doesn'ttake too long. Alright, so once that is finishedinstalling and downloading, we can just goahead and click Launch. And we can launchright into Visual Studio and see over here,it's asking me to sign in, you don't actuallyhave to sign in. So I'm just gonna click Notnow, maybe later. And then over here, we havea bunch of options. You'll see down here,there's this drop down, I'm just going toclick general. So just make sure it's on general.And then we can pick whatever style we wantto have, we can just go with the basics. SoI'll just stick with blue. And then I'm goingto click Start Visual Studio. Alright, sothis should go ahead and open up this littlestarting page, I'm just going to click outof this, we don't need to have this up here.And I'm going to go over here. And we're justgoing to click File, I'm going to click newproject. So we want to start a new project.And this is basically going to allow us towrite our applications. So over here in sortof Visual C sharp, you can just click here.And you'll see over here, there's an optionfor console app, this is what we want. Sodon't get too intimidated by all this differentstuff. Like I said before, Visual Studio isa very powerful program. And it can do a lotof stuff. But make sure you just click consoleapp, and we should be good. So I'm just goingto click OK. And actually down here, we cangive this a name. So I'm just going to callthis draft and then we could store it whateverwe wanted to store it. So when this loadsup, you'll see that we now have this fileopen. And this is just called program.cs andthat.cs extension stands for C sharp. Andthen down here we have a basic program. Sothis is essentially a very simple program.And it's sort of like the template for a program.And don't worry too much about what all thisstuff is. In the next video. I'm going totalk you guys through what all this stuffis what it means and we'll actually writeour first program but for now, we have everythingset up. So we're ready to go and right Toget started with C sharp development. Andthis tutorial, I'm going to show you guyshow to write your first C sharp program. We'realso just going to talk in general about whata program is, we're going to look at the differentinstructions that we can give to the computerand how those instructions are going to playout and allow us to write applications. Soover here, we basically just have our basicProject Setup. And I kind of went over howto do this in the last tutorial. And we'rebasically given this little text file, andthis is a C sharp file. So it's called program.cs.And that CS extension stands for C sharp.You'll also notice over here in our solutionexplorer, we have a bunch of different stuffhere. So I called my project draft. And thenover here, I have like this little propertiesthing, this references thing, really all weneed to worry about over here. And I knowthere's a lot of stuff over here is this guyright here, program.cs, that is the C sharpfile that we're going to be programming andthat's the file we're going to be using forthis course. And this is really all you needto worry about over here. And you'll see thatthis is actually populated with some codewith some text by default, you'll see up herewe have all of these little commands, it justsays using system using system collections,all this stuff, essentially what this is doingis it's just configuring the file. So youdon't really have to worry too much aboutwhat this stuff is up here. Just make surethat you leave it alone, you know, don't touchit. But basically, there's some things thatwe're going to have to use with C sharp andup here, we can specify that we want to usethem. So there's these things called system.And there's all these different things thatwe can use inside of there. But for the mostpart, you can just kind of leave this alonefor now, we'll talk more about what this islater in the course. But for now, you don'thave to worry about it too much. Down here,you'll see this as namespace draft, you'llnotice that this is actually the same nameas the project that we're using. And essentially,that's what this is saying. It's saying thatwe're in the draft project. And actually,this is doing some more stuff. Again, we'regoing to talk more about namespaces laterin the course. So you don't really have toworry about that too much. And really, youknow, all this stuff up here, you can canjust leave alone, you don't have to worryabout that in the beginning. And down herewe have these two curly brackets, and thesetwo curly brackets essentially just signifythat our like program is starting. So insideof these curly brackets, we can actually writesome code and the computer will be able toexecute that code. Here we have this keywordclass, and it's called program. Now a classis essentially just a container where we canstore a bunch of code. So inside of a class,we can write all of the code for our program,and it'll be able to be executed. So again,we're going to talk more about classes aswe go on through this course. But for now,just know that a class is essentially justa container where we can put code. Down herewe have this line of code here, it says static,void main. And this is actually what's calleda method or a function. Again, we're goingto talk more about methods and functions laterin the course. But this is sort of just likeanother container where we can put code. Andthis is a very important container. Becausethis container is where we can put all thecode that we want our program to execute.So this main method, or this main function,any code that we put inside of here, in otherwords, any code that we put inside of theseopen and closed curly brackets, is actuallygoing to get executed by our computer. Sowhatever code I want my program to have, Ineed to put it inside of this main method.So inside of these open and closed curly brackets.Now, I understand that like a lot of thisstuff doesn't make sense right now. And tobe perfectly honest with you, we kind of haveto just set our program up this way in orderfor it to work. It doesn't matter if thisstuff doesn't make sense. Like obviously,you're not going to understand what all thisstuff is. But just know that that's totallyfine. Like as a beginner, you're not expectedto know any of that you're not going to knowany of that through this course though, I'mgoing to be teaching you guys all of thisstuff. So by the end of the course, we'llunderstand what all this stuff is doing, whyit's important, why it's there. But for now,I just need you to trust me that we need tohave everything set up like this, in orderfor our programs to run an any code that we'regoing to write inside of our C sharp filethat we want to execute, I want to put inbetween these two curly brackets inside ofthis main block. Okay. So now that we've kindof talked about the structure a little bit,we've talked about, you know, some of thestuff that we needed to know, what I wantto do is actually write our first line ofcode. So we're going to go ahead and writea line of code, which is going to print somethingout onto the screen. So one of the thingsthat is really useful to do when writing aprogram is to print out information. And themost basic instruction that we can give thecomputer is basically telling it to printsomething out. So I'm going to go ahead anddo that down here. We're going to write ourfirst line of code. So I'm just going to sayconsole with a capital C dot right? line.And then we're going to make an open and closedparentheses. And I'm going to make a semicolon. Now inside of these opening closedparentheses, I'm going to make an open andclosed quotation mark. And I'm just goingto type out hello world. So essentially, whatwe're doing here is we're telling C sharpthat we want to write this text out onto thescreen. So let's kind of look through thisline of code. I'm saying console dot writeline. And this is an instruction. So essentially,I'm telling C sharp that I want to write aline out onto the console. And as we'll seein a second, the console is basically justa little window where we can see the outputof our program. I'm saying console dot writeline. And inside of these parentheses, I'mspecifying what I want to write out onto theconsole, or out onto the screen. And I'm basicallyjust saying, hello world. And then over here,I'm putting this semi colon. Now wheneverwe're writing a line of code in C sharp, wheneveryou're done writing that line of code, youalways need to end it with a semicolon. Sofor the most part, whenever you write an instruction,whenever you write a line of code, you'regoing to end it with a semicolon. And that'svery important. And as a beginner, you'regoing to forget to put the semicolon trustme, everybody does, but eventually, we'lljust kind of get used to putting it in there.Alright, so I'm going to go ahead and savethis file. And now we're going to actuallyexecute this program. So when I say executethe program, essentially what I'm doing isI'm telling the computer to go through andcarry out all of the instructions that wespecify. In our program, right now, we onlyreally have one instruction, which is tellingthe computer to write a line out onto theconsole. I'm gonna come up here, and you'llsee there's this start button. So this isgoing to be our best friend throughout thecourse, anytime I want to run my program,I'm going to go ahead and click this startbutton. So I'm just gonna click it. And whenI click this start button, my program is actuallygoing to run. And if you look there, you'llsee that a blank window popped up for justa second, I'm continuing to run it, essentiallywhat's happening is C sharp is printing outthe line hello world onto a little consolewindow that's popping up. But the problemis that our program is printing that out,and then the program is terminating. So thatwindow is going away. In order to keep thatwindow up. So we can see what's going on,I'm going to type out another line of code,I'm just going to type console dot read line.And basically what this line of code is goingto do is it's going to keep that little consolewindow up until I enter in a line of text.So now when I run my program, you guys willsee that this little black window up hereappears and it stays open. So before it waskind of flashing up and then disappearing.But now it's going to stay open. And you'llsee we're printing out hello world onto thescreen. Now, if I click the Enter key, soI'm just gonna click enter, this window isgoing to go away. So anytime I click enter,that basically tells our program that we'redone executing it. So we want it to go away.And that's basically all we have to do. SoI can write out instructions in here, I canwrite out lines of code, I can press the startbutton. And then I'm basically executing allof those lines of code. And then obviously,to get out of this, like I said, you can justlike type a space and type enter, or you canreally type anything, and just hit enter andthen the program will terminate. This is sortof our first C sharp instruction. And likeI said, console dot write line basically justwrites a line of text out onto the screen.And then we can include this console dot readline instruction in order to keep that windowup so we can see what we're printing out.Now that we know how to print out somethingonto the screen, I want to show you guys howwe can draw a little shape. So I'm actuallygoing to get rid of this. And I'm going togo ahead and copy this right line piece ofcode. And I'm going to paste it a few timesdown here. So we're actually going to usethis line of code to draw out a shape ontothe screen. So down here, I'm going to createlike a forward slash. And then up here, we'llcreate one. And I'm going to keep creatingthem in this little pyramid structure. Sonow you can see I have like a little pyramidand then I'm going to make a vertical barsgoing all the way down. So essentially, we'redrawing out like a little right triangle.And actually, you know, I want to put underscoreshere, so it's a little more obvious. So youcan see I'm saying console dot write line.And in each one of these instructions, I'mtelling the computer to write out a differentline. So over here, we're writing out likethe tip of the triangle. Over here, we'rewriting out the middle part of the triangle,and then the base of the triangle. So nowlet's go ahead and run this program. And you'llsee over here, we're actually able to printout this entire triangle. So just by usingthat one instruction console dot write lineinstruction, I was actually able to draw outan entire shape onto the screen. So now I'mgoing to go ahead and exit off of this. Andyou'll see down here how easy it was for usto write this program. Now, essentially whathappens is when I click that start button,C sharp is going to go into my program. It'sgoing to find this block of code right here.Main It's gonna go inside of these curly brackets.And it's going to execute each instruction.In other words, each line of code, one afterthe other. So it's going to start with thisfirst line of code. And it's basically goingto say, Okay, what does the user want me todo, they want me to write a line out ontothe console. And they want me to write thistext. So it's going to go ahead and writethat out onto the console, then when it'sdone with this instruction, it's going tocome down here and go to this second instruction,it's going to do the same thing. It'll executethat instruction, and then it'll go down here,execute this one and execute this one. Soessentially, what C sharp does is it executesall of the lines of code, all the instructionsthat we give it in order. And one of the thingsyou're going to learn is that when we're programming,the order matters. So the order in which youwrite these lines of code actually mattersa lot. So if I was to take this instructionover here, and I was to paste it up here onthe top, now, this is going to change theway that the shape looks. So instead of havingthat normal triangle, you can see we havethis kind of like funky looking shape, orthe base is up at the top. And that's becausewe changed the order of the program. Essentially,all a program is is just a set of instructionsspecified in a particular order. That's it.And as we go through this course, and as youlearn more about C sharp, you're going tofind more and more complex instructions thatyou can use. So the more complex instructions,you're able to give the computer and the better,you're able to organize them and order them,the more powerful your programs are goingto become. So obviously, we only really knowtwo instructions, we know this console dotwrite line, which prints something out inconsole dot read line, which basically pausesthe screen until we enter something. But justwith these two lines of code, we were actuallyable to draw out an entire shape onto thescreen. And that was pretty cool. The takeawaysfrom this tutorial is that a program is essentiallyjust a set of instructions that the computeris going to follow the order of those instructionsmatter. And in C sharp, the instructions thatare going to get executed by the computerare going to be inside of these open and closedcurly brackets in this main block of code.And that's sort of the bare basics of writinga C sharp program, we were able to print somethingout into the screen, we were able to pausethat little console until we told it we weredone. And now we can kind of go forward andstart learning more and more complex instructionsand more and more complex ways to build ourprograms. In this tutorial, I'm going to talkto you guys about variables in C sharp. Nowa lot of times when we're writing programsin C sharp, we're going to be dealing witha bunch of different data. So there's goingto be all sorts of information, all sortsof data values in our programs. And a lotof times that information, those data valuescan be kind of hard to keep track of and manage.So in C sharp, we have a special containercalled a variable. And a variable is basicallyjust a container where we can store some ofthat information. So I can store a piece ofdata or a piece of information that I wantto keep track of and manage in my programsinside of a variable. So in this tutorial,I'm gonna show you guys what variables are,why they're useful. And we'll look at kindof how we can work with them in our C sharpprograms. So down here, I have written outthis very basic program. It's basically justwriting out a bunch of lines of text, it saysThere once was a man named George, he was70 years old. He really liked the name George,but didn't like being 70. So this is basicallyjust a program that I wrote, which printsout a little story onto the screen. So ifI was to run this program, you'll see thatwe get this story it says There once was aman named George who was 70, etc. So I'm ableto print out this story onto the screen. Sothis is a perfectly functional program, we'veactually written a program which prints outa story, right, but let's say that I'm lookingat my story. And I'm thinking to myself, Hmm,I think I want to change the character's name.Well, let's say instead of having the characterbe named George, I want to change his nameto john. Well, I can just come up here, Ican search through my story, and find everyplace where I'm mentioning the character'sname, and I can change it to john. Cool. Sonow my story is updated. I went through Imanually changed the name to john, and everythingworks. But let's say I'm looking at it again.And I'm thinking maybe I want to try to appealto a younger audience. So instead of havingthe character be 70, why don't we have thecharacter be like 35. So once again, I canjust go through I can look through and everytime they mentioned the character's age, Ican just change it to 35. Here's the nextone. Cool. So I basically went through andI found out every place where the character'sname was mentioned, and I changed it to 35.Here's the problem though, in order to makethose changes in order to modify the character'sname and of the characters age, I had to gothrough and manually change it at every placeinside of my program. So every place wherethe character's name was mentioned, and thecharacters age was mentioned. I had to goin and manually change it. Now, this is finewith a story that only has four lines. Butimagine if this story had hundreds of lines.And the character's name was mentioned, like100 times or their age was mentioned 100 times,imagine then if you wanted to change the character'sname, or imagine even if you just wanted tokeep track of and manage the characters name,and it would be extremely difficult. So themore lines in the story that I write, theharder it becomes for me to manage the charactersname and the character's age. And these aretwo good examples of pieces of informationin our program. In order to make a situationlike this a lot easier, we actually have somethingin C sharp, called a variable. And a variableis basically just a container where I canstore a specific data value. And then whenI want to use that data value, instead ofhaving to actually like, type it out and typeout what it is, I can just refer to the variablesname. So I'm gonna show you guys how we cancreate variables, and how we can keep trackof and manage the different data in our programslike the characters name and the character'sage. So up here above my story, I'm actuallygoing to start creating a variable. And theway that we can create a variable is by givingC sharp some information. So this is goingto be a line of code. And the first pieceof information that I want to give to C sharpis going to be the type of data that I wantthe variable to be able to store. So remember,variables are just containers that we canstore values inside of. And different containerscan store different types of information.Some containers can store text, others canstore numbers, others can store like othervalues, like true or false values, we're gonnahold go ahead and create a variable that'sgoing to store the character's name. So Iwant to create a variable that can store text,because the characters name is text. And wecan do that by creating a string. So a stringis essentially just like a string of characters.And it's basically just plain text. So I'mgoing to go ahead and tell C sharp that Iwant to create a string variable. So I'm justgoing to type out string. And then what Ineed to do is give this variable a name. Soremember, these are containers. And generallywhen we're naming a variable, we want to nameit according to what's going to be storedinside of it. That way, we can identify what'sin the variable, I'm just going to call thischaracter name. And you'll notice here thatI'm separating these words. So the secondword has a capital letter. Alright, so I createdmy variable, and it's going to store a string,which is just plain text. And then I'm goingto set it equal to something. So I'm goingto say character name is equal to, and nowI'm going to give this a value. So I'm goingto give this a value, that's plain text, I'mgoing to make an open and closed quotationmark. And then whenever I write a line ofcode, I always want to end it off with a semicolon,just like that. Alright, now inside of thesequotation marks, I can write out the stringof characters in the string of text that Iwant to store inside of the character namevariable. So we're just going to store thecharacter's name, which is john. So I canjust type out john, up there. In additionto creating a variable to store the charactersname, I also want to create another variableto store the character's age. So let's goahead and do that. Now the character's ageis actually going to be a number, right, sothe character's age is a number. It's notreally plain text like this. And if we wantto create a variable to store a number, wecan create a variable called an integer variable.So I N T stands for integer. And an integeris basically just a whole number. So a numberthat doesn't have decimal points. And I'mjust going to go ahead and name this characterage. So again, giving it a name. And I wantto show you guys another way that we can createthese variables. So in addition to sayinglike string character name is equal to john,I can also just say, and character age, Ican put a semicolon here. And then I can comedown here and give this a value. So I couldsay, like character age is equal to, and nowwe can give this a value. So we said 35. Andyou'll notice that when I give this a numbervalue, I don't need these quotation marks,you only need the quotation marks with a string.So these are two different ways that I cancreate a variable and they're doing exactlythe same thing up here, I'm just saying stringcharacter name, and I'm giving it a valueright away. Over here, I'm doing what's calleddeclaring the value the variable on basicallysaying that we're going to have a variablecalled character age, I'm not giving it avalue right away. And then down here, I'massigning it a value of 35. So these two,this guy and this guy up here are doing exactlythe same thing. So now that we have thesevariables, in other words, now that we havecontainers, where we can store the differentvalues, or the different pieces of data thatwe're going to work with in our programs,I want to actually use those variables insideof our story. So I'm gonna show you guys how,in addition to printing out this plain text,I can actually print out the value that'sstored inside of the variable. So over here,you'll notice that I'm typing out there oncewas a man named john, but I don't want tohave to type out john anymore. I just Wantto be able to refer to that variable. So whatI can do is I can actually get rid of this.And I'm going to come outside of these quotationmarks. And over here, I'm going to put a plussign. And this plus sign basically means Iwant to like append some text, or I want toappend a value onto the end of this text overhere. And what I want to do is just put thename of the variable, so I'm just going totype out character name. And what this isgoing to do is it's going to print out thereonce was a man named, and then a space, andthen it's going to print out the value that'sstored inside of the character name variable.So it's going to print out, john. So let medemonstrate that, let's go ahead and run thisprogram. And you'll see over here, we're stillprinting out there once was a man named john,except I didn't have to physically type outjohn down here, all I did was use this plussign, and essentially just append on or peoplewill call this concatenate on the value thatwas stored inside of the character named variable.And this is extremely useful. So I could dothe same thing down here with this other occurrenceof the character's name, I can just say, charactername. And now over here, it's going to dothe same thing, it's going to say he reallyliked the name. And then whatever the valuethat's stored inside of this character namevariable, we can do the same thing for theage. So over here, you'll notice that I havethe age is 35. But remember, we created thisvariable up here to store that. So what Ican do is I can actually get rid of this.And I'm actually going to make to open andclose quotation marks here. And I'm goingto make two plus signs. And then in betweenhere, I'm going to type out character age,essentially, what I'm doing is I'm tellingthis right mine instruction that I want toprint out, he was with a space. And then Iwant to add in the value that's stored insideof the character age variable, which is goingto be 35. And then I want to add into thatyears old, so basically, what we're doinghere is called concatenating, a string, I'msaying I want to type this out, plus, I wantto type the value that's in here, plus, Iwant to print out this stuff over there. Andthen finally, we can do the same thing downhere. So I'm going to get rid of this. AndI'm just gonna type in character age. So I'vereplaced every occurrence of the character'sname and the character's age with these variables.So now let's go ahead and run our program.I'm just going to click this start button.And you'll see over here, we're printing outthe same exact story as before, it says Thereonce was a man named john, he was 35. He likedthe name john and 35. So I essentially justreplaced john and 35 with the variables thatare storing them. Now, what's cool about thesevariables is if I wanted to, for example,modify the character's name or the character'sage, I can just modify it up here. So let'ssay we wanted to change the character's nameto Tom. And we wanted to make him like 25.Well, now I only have to modify those twovalues, I only have to update them in onespot. And it's going to update throughoutmy entire story. So now the character's nameis Tom. And he's 25 throughout the entirestory, and the variables just make it a loteasier for us to keep track of and for usto manage those pieces of information. Now,you'll notice that I only created variablesfor the characters name and for the charactersage. And that's because those two pieces ofinformation are occurring multiple times inthe story, I didn't create a variable forthe word once or for the word man, becauseI just didn't need to, you know what I mean,that's not like a distinct piece of informationthat we want to keep track of. But the charactersname and the character's age are definitelypieces of information that we're going towant to keep track of and store. So that'ssort of how we can use variables to make iteasier to manage the data in our programs.Now I want to show you guys another cool thingwe can do with this. Let's say that halfwaythrough the story, I wanted the charactersnamed the change, I can actually come downhere and halfway through printing out thestory, I can modify the value of one of thesevariables. So I could say, character name,and I could just give this another value.So I can say character name is equal to Mike.And again, I need this semi colon at the endhere. Don't forget that. Now halfway throughthe story, the characters name is actuallygoing to change. So if we run the program,you'll see over here it says Tom, and thendown here, the name is Mike. So I was ableto update the value that was stored insideof our variable halfway through. And that'sanother cool thing is these variables, youcan give them one value and then later onin the program, you can change that value.So that's really the basics of working withvariables, we really learn two things, welearn how to create variables, and we learnhow to use them inside of like a print statementover here. Now there's a lot more to learnwith this. And actually in the next tutorial,I'm going to be teaching you guys about thedifferent types of information that we canstore inside a variable. So over here, westored a string of text and we also storeda whole number which is called an integerbut there's a few Other types of data thatwe can use and work with. So in the next tutorial,we're going to learn about all of that stuff.In this tutorial, I'm going to talk to youguys about data types in C sharp. Now in Csharp, we're gonna be dealing with all differenttypes of data and information. And generally,when you're writing programs, there's goingto be all different types of information thatyou're going to be working with. So I wantto talk to you guys today about the differenttypes of information and the different typesof data that we can represent and work within C sharp. So down here, I'm basically goingto be showing you guys all the different datatypes that we can use. And I'll be doing thatby creating variables. So a variable is justa container where we can store a data valueor a piece of information. And I'm going tobe creating different variables that can storethe different types of data that we can workwith in C sharp. So the first type of datathat we can work with is plaintext. So anytimeyou want to represent or, you know, use justregular old text inside of your programs,you want to use something called a string.So I'm just gonna say string. And I'll justcall it phrase. And I'm just gonna set itequal to a string. So a string is basicallyjust denoted using an open and closed quotationmark. And then inside of the quotation marks,you can just put whatever string you wantto represent. So in here, I could put like,draft Academy, and now this is going to bea string with the text draft Academy insideof it. So that's a string, and that's goingto come in handy a lot. Another type of datathat we can store is instead of a string oftext, just going to be one single character.So I want to create a character, I can justsay char, and maybe this could be like thegrade you get on a test or something. Andthen when I create a character, I want touse these single quotation marks, just likethat. And then inside here, I can put onesingle character, so I could put like an A,or a B, or a C, or something like that. Butthe important difference is that with a character,I can only put one single character, I can'tput a bunch of stuff, I can only put one,so any single character is going to work.But you need to make sure that there's onlyone in there, when you need more than onecharacter, then you want to move up to thestring. Alright, so that's the two ways wecan store plain text. So things like charactersand you know strings of characters, we canalso work with numbers, and the most basictype of number we can create is called aninteger. And an integer is basically justa whole number. So it's one of the countingnumbers like 12345, basically, an integerdoesn't have any decimals in it. So I canjust say, I n t like that int. And this couldbe like someone's age, for example. And somaybe someone's like 30. And you'll noticethat when I create a number, like any numbers,or you know whether it's an integer or anothertype of number, you don't need quotation marksaround it like you do up here. So you canjust type out the number as is. And you cando whole numbers like this, like an integer,we could also do negative numbers, and youcan just put the minus sign right in frontof it, and C sharp is going to be able tohandle negative numbers just fine. In additionto integers, we can also represent decimalnumbers. So a decimal number would be youknow, like 60.3 or something like that. Andinstead of storing inside of an integer, wecan actually store it in one of three datatypes. So there's actually three differentdata types that we can use to represent decimalnumbers. And they're called, there's a float,a double, and a decimal. And these basicallyallow you to store decimal points more andmore specifically, so These range from leastaccurate with the float to most accurate withthe decimal data type. So if you really wantto be super, super, super precise with thedecimal point that you're using, you wantto use a decimal point and this would be usedfor things like money, or you know, reallyanything that you need to be extremely exactwith you want to use a decimal, a float isgoing to be less precise. So it's going tobe able to be taken to, you know, a less preciseamount of decimal places. And then doubleis kind of just like right there in the middle.For the purposes of this course, I think forthe most part, we're just going to be usinga double. I think for most use cases, a doubleis going to be just fine. But like I said,if you're doing something you know, whereyou need to be extremely accurate, like withmoney or something, then you want to use thatdecimal. So I'm going to say double and Ican give this a name. So we can make thislike a GPA, right? Someone's GPA might belike a 3.2. So this is a good example of adecimal number, you can also make these justnormal numbers, so I can make it like 3.0.But anytime I'm using a decimal number, Ineed to include this point zero in there.So that's um, integers and doubles. And thoseare the two main types of like I said, numbers,we're gonna be able to represent whole numbersand then decimal numbers. And then we kindof touched on like the different types ofdecimal numbers. So after characters and numbers,we just have one more like core data typethat we're going to be representing whichis going to be called a Boolean. And a Booleanis essentially just a true or a false value.Now, a lot of times in programming, we'reactually going to Want to be able to storetrue false information. And this might notbe something that is super intuitive to youif you've never programmed before, but a lotof times storing information in the form ofa true or false value is going to come inhandy. So if I want to create a Boolean, Ican just say b o l, and Boolean is just a,you know, as it essentially just means a trueor false value. So I can say b, o l, and Ican give this a name. So we can call thislike, is male. And this Boolean will basicallytell us whether or not someone is a male.So I could say true if we're a male. Or youcould also say false. But those are the onlytwo values that they should have, it shouldeither be true, or it should be false. That'sit. And that's basically why Boolean 's areuseful because they can only have two values.So for the most part, I would say these arethe core data types that you're going to beusing in C sharp. Now there are a few otherdata types that we could get into, they'rea little bit more obscure, and they're notused as commonly as these data types. Forthe most part, you're going to be fine withjust strings, characters, numbers, and thenBoolean values 99% of the stuff that you wantto do, you're going to be able to do withjust this data. And as a beginner, you onlyreally want to concern yourself with thesedata types. Now I do want to point one morething out is you can represent these datatypes outside of variable. So if I came downhere and said, like console dot write line,I don't have to like store this type of datainside of a variable. If I don't want to likeI could just print out like a string likehello down here, like this isn't actuallystored inside of a variable, or I could printout like a number. Like if I wanted to printout 30, I could do that. And then when I runmy program, you can see we printed out justfine. These are what we would call constants.And a constant is basically just like a valuejust like this 30. It's not stored in a variable,we're not keeping track of it anywhere, it'sjust kind of written out. And we can do thesame thing for Booleans. So obviously, youdon't have to store this information insideof variables. A lot of times it's useful todo that. But if you don't want to, you canjust kind of use it like that. So that's thebasics of data types in C sharp, and theseare going to come in handy a lot really, withjust these types of data up here, you canwrite a bunch of awesome programs. In thistutorial, I'm going to talk to you guys aboutstrings in C sharp. Now strings are one ofthe most useful types of data that you'regoing to be working with in C sharp. So inthis tutorial, I want to just show you allthe ins and outs of working with strings,we're gonna look at some of the cool thingsthat you can do with them, and how you canreally leverage the power of strings insideof your programs. So down here, you'll noticethat I just have this little console dot writeline instruction. And basically, this is justgoing to write out some text onto the screen.So if I wanted to create a string, I can justmake these open and close quotation marks.And then in here, I can type out some text.So I could type out like draft Academy. Andnow when I run my program, it's going to goahead and print that out onto the screen.So anytime that I want to represent some sortof like plain text, or really any type oftext in my program, I can do it with a string.And there's actually some cool things youcan do with these strings. So let's say forexample, that I wanted to print out draftAcademy, but I wanted to print out draft onone line, and then Academy on the next line,I can use something called a new line character.So I could actually say backslash, N. Andthis is a special character that we can usein C sharp strings, which is basically goingto specify that we want to type out draft,then a new line, then Academy. So now whenI run my program, you'll see that draft andAcademy are printed out on different lines.So that can come in handy when you're writingout your strings. And there's also anotherway, so if let's say that I wanted to writeout a quotation mark, if I put a quotationmark here, you'll notice that this quotationmark effectively ends this string. And thenthis over here is just causing an error, Iwant to actually print out a literal quotationmark, that's not you know, delineating thestring, I can just use that backslash again.And now we'll be able to print out that quotationmark, no problem, just like that. So thoseare some cool little things that we can doinside of our strings. You can also take astring and store it inside of a variable.So a variable is just a container that youcan store different pieces of information.So if I wanted, I can create a variable overhere to say string. And we can just call itlike phrase. And I'm just going to set itequal to this text over here, which is justgoing to be draf Academy. And then down here,I could just print out the value stored insideof this variable. So I can print out the valuestored in the phrase variable. And we're stillprinting out draft Academy. So that's kindof cool. Another thing you can do with stringsis called concatenation and end cap and concatenationis the process of taking one string and thenappending another string onto the end of it.So you're essentially just adding two stringstogether. So for example, over here, I couldsay string phrase is equal to draft Academy.And then I could use this plus sign and thenthis is basically going to add another stringon to that. So I could say like, is cool.And now when I print out phrase it's goingto be printing out draf Academy is cool. Soit basically just added those two stringstogether, we would call that concatenation.And that can be really useful. Another thingwe can do in our programs is find out informationabout our strings. So sometimes, you mightwant to figure out different pieces of informationabout the string, figure out some attributesabout it. So let's say we wanted to figureout how many characters were inside of thisstring, I could just say phrase dot length,and that's with a capital L. And now whatthis is going to do is, it's actually goingto tell me how many characters are insideof this string. So now we should get like15. Yeah, cuz there's 15 characters, insideof draft Academy. So that's a really coolway, we can find out some information aboutthe string. In addition to finding out information,we can also use things called methods. Andwe're going to talk more about methods ina future tutorial. But essentially, all youneed to know right now is that a method isbasically a little block of code that we cancall, which is going to perform a specifictask. So these are basically like little predefinedsnippets of code that we can sort of tailedto execute, and then they'll do something.So we can use methods on our strings. Andthey'll either give us information about ourstrings, or they'll modify our strings insome way. So over here, if I want to use oneof these string methods, I can just say thename of the string, or I could also type outlike a literal string like that. And thenI can just say.so, I'm going to say phrase,dot. And now I have access to all of thesedifferent methods. So if I want to use one,I can just type out the name of the method.And I'll show you these can kind of do littlethings with our string. So let's say thatI wanted to take this string over here andconvert it into all uppercase, well, there'sactually a method that's going to be ableto do that for us. So I could say phrase.to,upper, and then we can make an open and closedparentheses. And now this is actually goingto take this string over here, convert itinto uppercase, and then print out the uppercasestring onto the console. So now when I runthe program, you'll see we get draft Academy,all in caps, you can also do the same thingfor lowercase. So I can say like to lowerand now to do the same thing. So it shouldall be entirely lowercase now, which it is.So that's one way that we could like modifythe value of a string, we can also find outsome more information about this string. Soimagine we wanted to figure out if this stringof text contained a certain like substringof text, right? So maybe we want to see ifthis string had the word Academy in it, Icould say phrase dot contains. And now whatI'm actually going to do is I'm going to givethis contains method, a piece of information.And this is called a parameter. So this overhere, this contains method will tell us whetheror not this phrase string contains like acertain set of characters or something. Andin order to use it, I have to tell it, whatI'm looking for. So I can say phrase dot contains.And in here, I could say, like, Academy, andthis is basically going to return a true orfalse value telling me whether or not thephrase draft Academy contains the word Academy.And we should get a true value back becauseit does. So you can see over here we get true.But if I set over here, like academies, nowall of a sudden, we should get false back.Because that string is not included in thephrase string, it's not included in draftAcademy. And that can be kind of useful, youcan like tell whether or not a certain stringcontains another string or another character.Another thing we can do is figure out thedifferent characters inside of a string. SoI'm going to get rid of that. Let's say thatI wanted to figure out what the first characterin my string was. Right? So let's say there'sa situation where I have a string like phrase,and I wanted to figure out what's the firstcharacter in that string? Well, I can actuallyaccess individual characters and print themout. So I could say like phrase and I canmake an open and closed square bracket. Andinside of here, I can just put the index ofthe character that I want to print out insideof the string. So if I put a zero here, thisis gonna tell me what this first characteris. So phrase, square bracket zero shouldbe printing out a capital G. And you see overhere it does, if I wanted to figure out whatthe third character in the string was, I cansay 012. So I can say two. And now this shouldprint out that are for us. And you can seewe get our so if you haven't caught on bynow when we're indexing a string, we actuallystart at zero. So if I was going to assignindex positions to each of the charactersinside of this string, I would say that theG character is at index position zero. Theeye character is an index position one theour character as an index position to thea character is an index position three, etc.So the first character this G is is actuallyan index position zero inside of the string.And that's basically just a way that C sharpand actually a way that most programming languagesindex strings. So when I say phrase zero,this is actually referring to this first character.So let's see if we could print out this aover here, well, it's basically going to be012345678. So this is going to be an exhibitioneight. So if I put an eight in here, now weshould be able to print out that capital A,which we do over here. So that's sort of howstring indexes work. And using this information,we can use another string method. So again,I'm just going to say phrase, dot and I wantto show you guys another method that we canuse it's called index of an index of is basicallygoing to tell us not only if a string containsa certain value, but it'll tell us at whatindex position that value is located insideof the string. So for example, if I came overhere and said, Academy, this is going to tellme at what index position Academy starts insideof this string. So when I run my program,you'll see that we're getting an eight overhere, and we just sort of saw that, that capitalA character started at index position eight.So basically, what this is saying is thatAcademy starts at 012345678. So it startshere, in addition to passing in a substring,like that, I could also pass in a character.And remember, a character is just an openand closed, single quotation mark. And theninside here, I could put like an F. And nowthis will tell me the location of the firstf inside of this string, so it'll give methat index, you can see we get four. And that'sbecause 01234, this starts at a four. Andthat can be pretty useful, there's also goingto be the situation where the character isn'tin there. So if I put a z in here, you'llnotice that there's no z up here. So in thiscase, we're actually just going to get a negativeone back and a negative one is always goingto signify that the character is not insideof the string. So that can be pretty useful.So that's how we can use phrase dot indexof, and that'll come in handy a lot. There'salso one more of these string methods thatI want to show you. And it's called substring.So I can say phrase, dot substring, I canmake an open and close parentheses. And I'mactually going to need to give this a value.So basically, what this will allow me to dois it'll allow me to grab a part of this string,so I can grab like, one part of the stringand then print that out onto the screen. Andwe can give this one parameter, we can givethis one argument, in other words, one pieceof information. And that's basically the indexwhere we want to start grabbing the stringat so let's say that I only wanted to grabthis academy word and print this out, well,remember, Academy starts at index positioneight, we already saw that. So this capitalA is actually index position eight in thestring. If I put an eight in here, this isnow going to grab the characters startingat eight and going to the end of the string.So now, we should just print out Academy,which we do down here. You can also in additionto just passing in the starting index, youcan pass in a length. And you'll notice thatI'm just using a comma here, and now it'sgoing to delineate that I want to pass inanother value. So I'm passing in the startingindex. And I can also pass in how many charactersI want to grab. So I can say I want to startgrabbing the characters at eight. And let'ssay that I only want to grab three characters.So over here, I can put a three. And now we'regoing to start at eight, and we're going tograb 123 characters, so we should get ACAprinted out onto the screen. And you can seethat we do so that substring method can comein handy. So that's kind of the basics ofworking with strings. And you know, so assoon as you guys kind of how we can work withthem different things we could do like concatenation.And we can also print out things like newlines, we also looked at getting informationabout a string, like the length, and you know,individual characters in the string, we talkedabout the string indexes, we also talked aboutdifferent methods that we can use to do differentthings with our strings. So hopefully, thatkind of gets you up to speed with why stringsare awesome and how they're useful. And tobe honest with you, there's a lot more ofthese little methods that you can use. Andif you want, you can just go online and GoogleC sharp string methods and you'll find likea huge listing of you know, probably at leastyou know a few dozen of these different methodsthat you can use to either find out informationabout or modify your strings. In this tutorial,I'm going to talk to you guys about numbersin C sharp a numbers are one of the most commontypes of data that you're going to be workingwith in your C sharp programs. So in thistutorial, I just want to kind of give youguys a full walkthrough of you know how touse numbers, the different types of numbersthat we can use, and we're also gonna lookat some cool things that we can do with numbers,things like you know, complex math operations.And we're just dealing with numbers in general.So it's gonna be pretty cool down here, Ijust have a basic program, it just is basicallywriting out a line of text. So if I wantedto, for example, like write out a number,I can just represent a number by just typingit out. So I could say, like 40, or 20. OrI could say, like negative 5.763, really anytype of number I can work with. And there'sreally two main types of numbers, there'sa whole number, which we would refer to aslike an integer, and then there's a decimalnumber. So those two different types of numbersare going to be really useful in our C sharpprograms. But it's important that you notethat C sharp does distinguish between thosetwo types of numbers. So there is a big differencebetween working with whole numbers and workingwith decimal numbers. And it's something thatyou just want to be aware of, as you sortof go through and write your programs. Andso you know, basically, I could just typein a number here like 50, and then I'd beable to print it out onto the screen justover there like that. So numbers are prettyeasy to work with. We can also do math withnumbers, so I could say like five plus eight.And now instead of printing out five pluseight, like the literal text five plus eight,C sharp is actually going to go ahead andperform this math operation for us. So it'sgoing to print out the result of adding fiveand eight together. So we're going to get13 over here. And we can use addition likethat, we could also use subtraction, whichis just that hyphen, we could use a forwardslash, which would mean division. And we couldalso use a Asterix, which is going to representmultiplication. So any of those differentoperations, the four basic math operationsyou can use, we can also use another operator,which is called the modulus operator. So forexample, if I could say, like, five, and thenI can put a percent sign here, and I can saytwo, and we would read this as five mod two,and this modulus operator right there, essentially,what this is going to do is it's going totake five, it's going to divide it by two,and it's going to give us the remainder. Sofive divided by two is going to be two witha remainder of one. And that's exactly what'sgoing to get printed out. So we should justprint out one over here, which we do. So sometimesyou might be interested in getting the remainderof a particular division operation. And thisis going to go ahead and do that for us. Wecan also represent like mathematical equations.So one thing we can do is specify order ofoperations. So if I was to say like four,plus two, times three, actually, what's goingto happen is the multiplication is going tohappen first, and then this addition is goingto happen. So it's going to be three timestwo, six, plus four, so we should get 10.And that's just sort of following normal orderof operations rules. But if I wanted to changeup the order of operations, I can use parentheses.So I could say like four plus two, which isgoing to be six, and now it'll be six timesthree. So we're going to get 18, instead ofgetting that 10. So you can use those parenthesesto sort of change around the order that differentcalculations are getting performed. And thosecan be pretty useful. I also want to talkto you guys about the difference between usingintegers and using decimal numbers. So likeI said, an integer is just a whole number,a decimal number would be, you know, a numberthat has a decimal on it, something like that.And actually, like I said, C sharp does distinguishbetween these two types of numbers. So ifyou're adding or subtracting or multiplyingor doing some sort of mathematical operationwith an integer, and a whole number, sometimesthe results you get are going to be a littlebit different. So if I was just to say, like5.0 plus 8.1, if I was to perform a math operationwith two decimal numbers, then I'm going toget a decimal answer back. So I'm going toget like 13.1. But if I was to perform a mathematicaloperation with an integer and a decimal, sofive plus 8.1. And you'll notice that thisis now an integer because it doesn't havea decimal point. Again, we're going to geta decimal back. So I'm going to get a decimalnumber back just like that. But when we domath operations with two integers, then we'realways going to get an integer back. So ifI said five divided by two, and you'll noticethat these are both integers, I'm actuallygoing to get an integer answer back. So really,this should be like two point something rightshould have some long decimal point. But whenI actually run my program, you'll see thatI'm getting an integer value back, I'm gettinga two back. But if I was to convert this toa double, so if I said 2.0. So now this isgoing to be a decimal number, we're goingto get a decimal answer back. So that's basicallyhow that works. So any math operation thatyou do with two integers, no matter what you'regoing to get an integer back, but if you doa math operation with a decimal and an integer,then you'll always get a double back. Andthat'll kind of come in handy as you're workingwith these different types of numbers. Anotherthing we can do is we can store numbers insideof variables. So I can create a variable uphere let's create one for int. So I'm justgonna say int num and I can give this a valueof like six right so now this container numis storing the value of six And then I canprint that out just like I normally would.So I can just say num down there. And it'llprint out that six. There's another cool operationwhich we can do, which will basically allowus to increment this number. So down here,I can say num plus plus. And basically, whatthis is going to do is it's going to add oneto the number. So now instead of being six,since we're adding one to the number, thisis going to be seven. So when I run my program,you see we'll get seven. And you can do asimilar thing with minus minus, so I couldsay like num, minus minus, and now insteadof getting a six, we would get a five. Andthose are going to come in handy, just aslike a shorthand as we go through our C sharpjourney. So those are sort of the basics ofyou know, working with numbers. And you cansee we can store them in variables. And wetalked about, you know, interacting betweenintegers and decimal numbers. And I also wantto show you guys some other stuff we can do.So a lot of times in our programs, we're goingto want to be able to perform different mathoperations. So there's all sorts of math operations,you know, like using exponents, and usingthe square root or you know, even doing likelogarithmic stuff, or sine, cosine, tangentstuff, like there's all sorts of math thingsthat we might want to be able to do insideof our programs I'm gonna show you guys, there'sthese things called methods. And a methodis basically just a block of code that's goingto perform a specific task. So I can do what'scalled call a method. And when I call a method,it's basically going to like perform a specifictask or a specific function for me. And there'sa bunch of these different math methods thatwe can use in our C sharp programs. And theway that we can get access to them is justby typing out math with a capital M. And thenI can say, dot, and now I have access to allthese different math operations. So you'llsee down here, I can like scroll down throughthis list, and there's all these differentthings that I can do, I'm going to show youguys a couple of these cool math methods iswhat they're called. And you can kind of seewhat they do. So one is just math dot abs,and the stands for absolute value. So I canmake an open and close parentheses and insideof here, I'm going to put a number. So ifI said like negative 40, this is going togive me back of the absolute value of negative40, which is just going to be 40. As you cansee, there's another one, which is calledpow, and this stands for power. So I'm actuallygoing to be able to give this two numbersand it's going to spit out the first numbertaken to the second number. So if I said likethree and then to over here, this is goingto give me back three raised to the secondpower. So we should get nine. And you cansee we do and that's this will also work withlike decimal numbers. So I can say like 3.8raised to the second power. And now we shouldbe able to run this as well. So 14.44. Andyou can also do the opposite. So we couldsay like Sq RT, this is going to Stanfordsquare root. So if I put like a 36 in here,now, I'm actually going to get back to thesquare root of 36. So we should get six back.And we do, there's also another useful method,which is called min max. And with Max, youcan actually pass two numbers into these parentheses.So I could say like four and 90, and Max isactually going to spit out whichever one isbigger. So it'll tell us which number is thebiggest. And so this should give us 90, asyou can see down there. And that can comein handy, there's going to be a lot of situationsin C sharp, where you might have two numbers,maybe they're stored inside of variables,and you don't necessarily know which one isbigger. So you can use that math functionto figure that out. There's also another onecalled min, and that just does the opposite.So now this will give us the smaller of thetwo numbers. So we're going to get four back.There's one more that I want to show you guys.It's called math dot round. And this is areally great way to round numbers. So whenI say math dot round, I can pass this likea decimal number like 4.3. And this will roundit just according to standard rounding rules.So you can see, we get four. But if I wasto up this to like 4.6, now we're gonna goahead and get a seven or a five back. So weget the five back there. So those are justsome basic, you know, math operations thatyou can do. And you can see I'm using thisVisual Studio text editor when I just saymath, and then I click this dot, you can seeall of these different options are showingup down here. So there's all these differentmethods that we can call, I mean, there'sall sorts of stuff we can do. And you cankind of just like play around with each ofthese, like, see what they do. But for themost part, like any major math operation thatyou're going to want to be able to do, there'susually going to be a method for it, or atleast a method in here to help you with it.So you definitely want to check that out.And you can also just google like C sharpmath methods on line and you'll find a hugelisting of them. So that's sort of the basicsof you know, using math and then also workingwith numbers. Again, numbers are extremelyimportant. So you want to make sure that you're,you know, up to date and sort of up to speedwith how to use them and how they interactwith each other and all that stuff in theC sharp. In this tutorial, I'm gonna showyou guys how to get input from a user in Csharp. Now one of the cool things about Csharp is we can actually have our programsinteract with the user. So I can run my program.And I can actually like give it some information.And it can use that information to do differentthings. And when you think about it, mostprograms that you probably use on a dailybasis are going to allow you to input informationinto them. And then depending on the informationthat you input, they're going to do differentthings. So today, we're going to look at themost basic form of that, which is just, youknow, allowing the user to basically liketype in a value, and then we can use thatvalue to do something. So down here, I havea simple program set up, you'll see I'm justsaying console dot write line, and I'm writingout Hello. And then down here throughout thiscore. So far, I've always included this lineof code in our little programs. And basicallywhat this line of code has been doing is it'sbeen allowing us to see the output of ourprograms, right. So if I include this readline, when I run my program, that I can seewhat gets output so I can see Hello, rightsort of stays on the screen. But if I wasto get rid of this line, like if I removethis, when I click the start button, you'llsee that that window, like pops up reallyquick and then disappears. And that's becausewe're essentially executing this line of code.And then once that line of code has been executed,there's nothing else to execute, right, there'sno other instructions for the computer tolike, carry out. So essentially, the programjust terminates, and then that window disappears.We've been using this console dot read lineinstruction in order to keep that black windowup on the screen in order to keep the consoleon the screen. Because what this line does,is it actually waits for the user to enterin a line of text. So this line essentiallypauses the execution of our program, and waitsfor the user to enter something. So if theuser hasn't entered something, then our programis essentially just paused. So actually, ifyou guys watch over here, my program is essentiallypaused. But if I was to enter something, andthen click enter, the program terminates,right, because now this line of code downhere has finished executing. But what's coolabout this line is, like I said, it pausesthe program. So we can sort of see what'shappening. Another thing that this line ofcode does though, is it allows us to enterin a line of text. And we can actually usethis instruction over here to get input fromthe user. So I'm going to show you guys howwe can do that. In this tutorial, I want tobasically design a little application, that'sgoing to ask the user for their name, it'sgoing to get their name, and then it's goingto say hi to them. So I'll basically be ableto type in my name, and the computer willbe like, Hey, Mike, what's up. So the waywe can do that is with a couple steps, thefirst thing we want to do is prompt the userfor information. So I'm basically just goingto write out a line and I'm just gonna sayconsole dot write. And you'll notice beforewe were using console dot write line. Nowessentially, the difference between writeand write line is that when we say write line,this is going to print out a line of text,and then it's going to go on to a new line.So it's basically going to print out and thenwe'll go on to a new line, when I just sayconsole dot write, it's not going to go offto a new line, it's just going to kind ofprint out on the same line. And you guys willsee what I mean in a second. So I'm goingto use console dot write because I'm basicallygoing to be prompting the user. So I can justsay, enter your name, and then I'm going tomake a colon. So this is going to be our promptfor the user. Now the next thing that we wantto do is we want to be able to allow the userto enter in a line of text. So I can do that,like I said, with console dot read line, justlike that. And this is going to pause theprogram and wait for the user to enter ina line of text. But here's the thing, I don'tjust want to let them enter in the line oftext, I want to be able to take the text thatthey enter in store it inside of a variable,right? Like if they just enter text, it'sno use to me if I don't know what they entered.So I want to be able to store the value thatthey entered somewhere. And we can do thatwith a variable. So whenever we use this consoledot read line, it's basically going to getthe line of text that they enter as a string.So it's going to store the line of text thatthe user enters as a string of characters.So I'm going to create a variable. And we'rejust going to call this name and I'm goingto set this equal to console dot read line.So I'm saying string name is equal to consoledot read line just like that. Now the lastthing I want to do is I'm actually going towrite something out to the screen. So I'mjust going to say write line. And over here,we're going to print out Hello, and then we'regoing to print out the name that the userentered. So I'm basically just going to printout Hello, plus name. So basically, the useris going to enter in Name. And then we'regoing to say hi to the user. And you'll noticeI'm keeping this relined down there, justso we can see what the output is. So let'sgo ahead and run this program. And we'll seewhat happens. So over here, it says, enteryour name. And you'll notice over here, it'sletting me enter this on the same line asthis prompt. And that's why we use that consoledot write instead of console dot write line.So over here, I'm just gonna type in my name,my name is Mike. And now when I click enterthe value, Mike is going to get stored insideof that name variable. And then we're goingto be able to print it out on the screen.So you can see down here, we're printing outHello, Mike. And that's essentially all weneeded to do to get this program to work.So we use console dot read line, which pausethe program and let the user enter in a lineof text. When they hit enter, the value thatthey entered gets stored inside of this namevariable, and then we printed it out ontothe screen. So that's pretty cool. And wecan actually do this as many times as we want.And so if I wanted, I could get another pieceof information from the user. So I'm goingto do that, I'm going to copy this, and we'llcome down here. And this time, I'm going toask them to enter in their age. So over here,we're going to create another string, andwe're just going to call it age. And again,I'm just gonna say console dot read line.So now in addition to having their name, wealso have their age. So I can say hello, name.And then I can basically tell them how oldthey are. So I can say you are, and then we'llprint out their age. So now we're saying hello,whatever the name is, you are, whatever theirages. So let's go ahead and run this program.Now we're getting two pieces of informationfrom the user. So it says, enter your name.So we can enter in like john, and let's sayjohn is 40 years old. So now when I clickenter, we're going to have two values. Andwe'll be able to print them out. So it says,Hello, john, you are 14. So that's sort ofthe basics of getting input from the user.And again, remember what I said, when I useconsole dot read line, it's taking whateverthe user enters, and it's storing it as avariable. So this is always going to be avariable, it's always going to get the informationthat they enter as a variable. And that'swhy we had to store both of those pieces ofinformation inside of strings. But there'sactually a way that we can get other typesof information like numbers from the user.And in the next tutorial, we're going to builda little calculator game. And I'm going toshow you guys how we can actually get numbersfrom the user. But for now, that is sort ofthe basics of doing this. And you probablyjust want to practice with this and maybemake it a little application of your own.In this tutorial, I'm going to show you guyshow to build a basic calculator in C sharp.So we're basically going to build a littleprogram where the user can enter in two numbers.And then our program will add them togetherand spit out the answer onto the screen. Soshould be kind of cool. And we're also goingto talk about getting numbers as input fromthe user. So this is going to be a prettycool tutorial. So down here, before we startbuilding this, I actually want to show youguys how we can convert a string into a number.And this is a technique that's going to comein handy for this application. Essentially,like if I had a string that had a number init, so like 45, or like 45 point 80, whatI could do is I can actually use a specialmethod in C sharp that would be able to convertthis into an actual number. And the reasonthat's useful is because like if I had consoledot write line, like if I had two stringsthat had numbers inside of them, like 43,plus 56. If I tried to add these two together,this is just going to concatenate the strings.So you see over here, we get 4356. So it'snot adding the two numbers that are in heretogether, it's just like concatenating thestrings together. So in certain cases, you'llhave numbers that are kind of trapped insideof strings. And actually, we're going to havethat situation in this tutorial. And so youwant to be able to get the numbers out ofthere so that you can like do math with them.So I'm gonna show you guys how we can converta string into a number. So actually over here,why don't we come down here and we're goingto make a number variable. So I'm just goingto make an integer. And we'll just call thisnum and I'm going to set it equal to a string.So I'm going to set equal to a string thathas a number in it like 45. You'll see overhere, C sharp is yelling at us because thisnumber is actually a string so it's not goingto be able to be stored inside of an integervariable. So we need to convert this intoa integer. And the way that we can do thatis just by typing out, convert like that notend with a capital letter, and then dot andnow we need to specify what we want to convert.So you'll see over here there's a bunch ofoptions like to in 32, two and 16 to doubleto decimal to string, this little convertfunction is basically going to allow us toconvert different values to other values.In our case, we want to convert this to aninteger. So I'm just going to say convert.to,int 32. And that was one of the options thatwe had over here. And then I'm going to makean open closed parentheses around the actualstring. So when I do this, this is going togo ahead and convert the string inside ofhere into an integer. And just to note, thestring that we put in here has to have a numberinside of it. Like if this was just somethinglike that, this isn't going to work, we'reactually gonna get an error. But if I havea number in here, like 45, then this is goingto work just fine. So if I was to come downhere, now I could actually use this as aninteger. So I could say num, plus six. Andnow we'll actually be able to do this mathoperation. So you can see we get 51. And that'sessentially how we can convert a string intoan integer. And just so I can point this out,like if this didn't have a number inside ofit. Or even if it did have a number insideof it, but the number had like text next toit, this isn't going to work. So we're actuallygoing to get an error. And you can see theprogram wasn't able to run, because it saysdown here input string was not in correctformat. So that's just something to keep inmind. And later in the course, we're actuallygoing to talk about how we can fix somethinglike this and mitigate it. But for now, we'rejust going to assume that the string is goingto be formatted correctly. And I'm just goingto exit out of this exception. Alright, sothat's kind of an explanation of how we canconvert a string into an integer. And we'reactually going to be able to use this in ourprogram. So like I said, we're going to builda calculator program that's going to allowthe user to enter in two numbers. And thenwe'll take those numbers, add them togetherand print it out. So the first thing I'm goingto do is just print out a prompt, so I'm goingto say console dot write. And I'm actuallyjust going to use right, and then over here,I'm just gonna say enter a number. And nowwe're prompting the user to enter a number.And what I want to do now is I want to beable to get the number that they enter. SoI'm just going to say console dot read line.And this is going to go ahead and wait, it'sgoing to pause the program until they enterin a line of text. And so what I actuallywant to do is I want to store the number thatthey enter inside of a variable. So I'm goingto create a variable over here, and and we'rejust going to call it num one. And I'm goingto set it equal to console dot read line.But you'll notice over here, we're gettingan error. And the problem is that consoledot read line is going to give us a string.So console dot readline takes whatever theuser enters and turns it into a string. Andthat's sort of the value that we have. Ifwe want to eventually add these numbers together,we're not going to be able to use a stringlike I showed you before. So we're actuallygoing to have to convert this into an integer,which now we know how to do. So I can justsay convert.to, and 32. And I'm going to surroundconsole dot read line, this whole thing withparentheses. So now this whole thing is surroundedwith these parentheses, and it's going toget converted into an integer. And that'sbasically all we need to do for that. So nowI'm going to copy this and we'll be able toget the second number. So I'm gonna come downhere, and I'll just say enter another number.And we're going to call this one, two. Sonow we're prompting the user for a number,we're getting that number and turning it intoan integer. And we're doing the same thingdown here. So the last thing we want to donow is just print out the answer. So I'm goingto go ahead and say console dot print lineor write line. And I'm just going to writeout number one plus number two, because weconverted these guys into integers, we'regoing to be able to add them together. Solet's go ahead and run this program. And we'llsee how we did. It says enter a number. Solet's enter in a 10 and insert another number.So why don't we insert a three. And so nowit's going to convert both of those into integers,and add them together and we get 13. So lookslike the program's working out pretty well.There's actually a problem with this program,though, if I was trying to add a integer numberwith a decimal number. So if I said like four,and over here, I put in like a 2.6. This isactually not going to work. So you'll seethe program isn't actually printing anythingout. That's because the program is stalling,we didn't enter in a correct value, we inserteda decimal value and this can't be convertedinto an integer. So you'll notice that theprogram over here is stalling. And basically,that's because we entered in a decimal number.So if I wanted to allow this program to beable to handle decimal numbers, instead ofconverting these two integers, I'd want toconvert them to doubles. So I could changeboth of these two doubles like this doubledouble. And instead of saying convert dottwo and 32 I could say convert.to double andsame thing down here. And now we should beable to work with decimal numbers in our program.So let's see if we can do that. I want toadd two And 3.6. And now we're able to addthose two together. So in certain circumstances,you might want to have a situation where theuser can only answer an integer numbers. ButI think in most cases, you'd want to use doubles,just like I did down there. And you can seehow easy it is to convert them into doublesinstead of integers. So that's a very basiccalculator. And that kind of gives you anidea of how we can get numbers as input froma user. In this tutorial, I'm going to showyou guys how to build a little mad libs gamein C sharp. Now, if you're not familiar withMad Libs, it's basically a game where youcan enter in a bunch of like random wordsand maybe like a couple nouns and adjectiveand adverb, and you'll take all those randomwords, and you'll kind of sprinkle them inthroughout a story. And generally, becauseyou're entering in random words, the storyends up being like pretty funny. So I actuallyhave an example of a Madlib over here on myweb browser, you'll see it's basically justa little story and you kind of sprinkle indifferent words like this one that's askingfor an adjective or a plural noun or a celebrityname. So these are pretty fun. And I actuallywant to show you guys how we can build a MadLibs for ourself in C sharp, it's actuallyreally easy. So down here, I have a littleprogram set up. It's basically just writingout this story. So it's writing out Rosesare red, violets are blue, I love you. Andthis is sort of like a classic little poem.But I think this poem would be a lot betterif we turned it into a Mad Libs. So how aboutinstead of saying Roses are red, we wouldsay roses are and we'll let the user choosea color. And instead of saying violets areblue, we'll let the user choose a plural noun.And instead of saying, I love you, we'll letthe user choose a celebrity that they're goingto love. And so will basically allow the userto enter in three random words, and then we'llsprinkle them in through our story. And hopefully,it'll be pretty funny. So let's think abouthow we can build a Mad Libs, essentially,what we're going to do is we're going to haveto prompt the user for input, we're goingto have to take that input and store it insideof variables. So let's go ahead and do that.And, essentially, what we're going to needis we're going to need three variables tostore the color, the plural noun and the celebrity.So I'm actually going to show you guys oneway that we can do that. And we're actuallygoing to declare these variables first. Andthen we're going to give them value. So uphere, I'm just going to say string. And I'mbasically just going to tell C sharp thatI'm going to want to use three variables inmy program. So I'm going to want to use onecalled color, I'm going to want to use onecalled plural noun. And I'm going to wantto use one called celebrity. And I'm justgonna put a semicolon after this. And if you'vebeen following along with this course, wehaven't necessarily been doing you know, exactlythis, every time we were creating variables.But this is one way that we can create a variable.And we're basically just declaring the variablesup here. And now down here, we're going togo ahead and give them values, and actuallywant to let the user give these variablestheir values, because the user is going tobe entering in the color, the plural nounand the celebrity. So let's go ahead and writeout some prompts. So I'm just going to sayconsole dot write. And in here, I'm goingto ask the user to enter a color. So I'm justgoing to say, enter a color. And after I promptthem, I want to wait for them to enter inthe color. So I'm just gonna say, consoledot read line. And this is basically goingto pause the program and wait for them toenter in a line of text. But I want to takethe line of text as they enter in store itsomewhere. So I'm going to store it insideof this color variable. So I'm just goingto say color, which we declared up here, anddown here, I'm going to give it a value. SoI'm gonna say color is equal to whatever theuser enters. And we can basically do the samething for the other two. So I'm going to goahead and copy this. And down here, I'm justgoing to paste it. So I'm actually gonna makesome new lines. And so now, instead of a color,we're going to want to get a plural noun.And then down here, instead of setting thecolor variable equal to whatever they enter,now, we're going to store this value insideof the plural noun variable. And then finally,down here, instead of asking for the color,we're going to ask for a celebrity. And we'regoing to store that inside of the celebrityvariable. So now we've prompted the user toenter in those three things, we've storedall of their responses inside of variables.So the last step is to put those guys intoour story. So over here, I'm gonna say rosesare, and I'm gonna use the color. And theninstead of just saying plural noun, I'm gonnasay, plural noun, plus our blue. And thenfinally, we'll do the same for the celebrity.So I'm taking the variables and I'm sprinklingthem in through this story. So depending onwhat the user enters, this story is actuallygoing to be a little bit different. So Let'sgo ahead and we'll run this program and we'llsee how we did. So over here it says entera color. So why don't we enter in like magenta?Enter a plural. Now let's do microwaves andenter a celebrity, why don't we do like TomHanks. So all of these values that I enteredare getting stored in the corresponding variables.And now when I click enter here, it shouldprint all of them out inside of our Mad Libs.So I click Enter, and it says roses are magenta,microwaves are blue, I love Tom Hanks. Sowe actually built a fully functioning madlibs,right, I can go in, I can enter in any valuesthat I would want, and those are gonna getsprinkled into the Madlib. Now over here,we built a very simple madlibs. Right, thiswas, you know, essentially three inputs, andthen we put them into a very simple poem.But you can see how you can use this sametechnique in order to ask the user to enterin like maybe 10 or 20 different words, andyou can make a way more complex story downthere. So essentially, with very few linesof code, I mean, this is probably, you know,10 lines of code, we were able to write outan entire Madlib in C sharp. In this tutorial,I'm going to talk to you guys about arraysin C sharp, a lot of times when we're runningprograms in C sharp, we're going to be dealingwith all types of data, a lot of times we'regoing to be dealing with large amounts ofdata. And one way that we can manage and keeptrack of the data in our programs is by usingvariables. But the one problem with variablesis that they can only store a single value.So I can create a variable like an integervariable or a string variable. But I couldonly store one integer or one string insideof that variable container. And a lot of times,if we're dealing with huge amounts of information,we're not going to want to have to createlike hundreds or 1000s of variables. So it'sactually another container, another type ofdata structure that we can use in C sharp,we'll just call it an array. And an arrayis basically a structure that allows us tohold multiple pieces of information in thesame container. So unlike a variable thatcan only hold one value, an array can holdmultiple values. So you can hold 10 or 100,or 1000, or even a million values inside ofan array. So a good way to think of an arrayis just a collection of individual variables,right, so an array can hold like 20 differentvalues that you would normally have to putinside of a variable. So I'm gonna show youguys how we can create arrays, we'll talkabout sort of the basics of using them. AndI'll kind of get you guys up to speed withusing arrays in C sharp. So down here in myprogram, I'm going to go ahead and createan array. And remember, an array is just acontainer that can hold a bunch of piecesof information. So we create an array verysimilar to how we create a variable, the firstthing we have to do is specify the type ofinformation or the type of data that the arrayis going to hold. So we can use all the basicdata types string in double Boolean, we canuse all those things. In our case, let's makean array of integers. So I'm just going tosay int, and then I'm going to type a space.Now whenever we're creating an array in Csharp, we always need to let C sharp knowthat. So the way that we can tell C sharpthat we want to make a variable instead ofan array is by making an open and closed squarebracket. And that's going to signify thatthis is going to be an array. And then overhere, I can type the name of the array thatI want to create. So I can give this arraya name. So why don't we just call this likelucky numbers, we'll create an array that'sgoing to store a list of lucky numbers. Inorder to give this array some information.There's actually a couple of different wayswe can assign values to arrays, I'm goingto show you guys all the ways in this tutorial.But the most basic way is to just make anopen and closed curly bracket. And then insideof here, we can start typing out the valuesthat we want to put inside of our array. SoI can just start typing out some numbers,and we'll be able to store them all in thesame container. So over here, I'm just goingto tell you like for a 15 1620 3042. So I'mjust typing out a bunch of different integers.And you'll notice that I have one value here,and then I separate it with a comma, and thenI can put another value. So all of these wouldbe considered elements inside of the array.So I would say like, four is the first elementin the array, eight is the second elementin the array. And we can delineate the elementsusing these commas. And essentially, now wehave a container, we have this lucky numberscontainer, which is able to store all of thesevalues. And this makes it really easy forus to manage and maintain large amounts ofinformation. So I mean, over here, I onlyhave like maybe six numbers, but if I wantedI could put hundreds or 1000s or even millionsof values inside of one of these arrays, andthey're extremely useful. So now that we lookedat how we can create an array, let's talkabout how we can access the individual elementinside of an array, right, because this arrayis going to be no use to us unless we canactually get access to each of these values.So I'm going to show you guys how we can dothat. And I'm just going to do a console dotwrite line. So we'll just print out particularvalue onto the screen. So if I want to accessa particular value, I can just type out thename of the array. So in our case, lucky numbers,and then I want to make an open and closedsquare bracket. And inside of this squarebracket, I want to give a number so I'm basicallygoing to specify the index of the elementthat I want to print out or the index of theelement that I want to access. So let's sayI wanted to access this element four righthere, it's the first element in the array,I'm going to put a zero here. So this fourelement is at the zeroeth position, it's atthe zero index inside of the array. So nowwhen I run my program, you'll see we're printingout four, so we're printing out that firstelement in the array. And so the way thatwe index these array elements is startingwith zero. So if you've been following alongwith this course, you'll know that this isthe same way we index strings. So I wouldsay that four is at index position, zero inthe array, eight is at index position. 115is an index position to 16 at three, etc.So we start counting. In other words, we startedthe indexing at zero. So over here, I couldsay like lucky numbers, two, and now we'regoing to get 012, we're going to get this15 back. So we'll be printing out that 15you can see over there. So essentially, whenwe access an element in the array like this,it's a lot like we're accessing a variable.And it's actually you can think of each oneof these elements in here as their own kindof separate variables. And you can do everythingwith them that you could do with normal variables.So another thing we could do would be to updateone of these elements. So for example, ifI wanted, I could go ahead and change oneof the values over here. So let's say we wantedto change this element, we wanted to changeeight, we could actually just say, lucky numbers,and I'll make an open and close square bracket,I'm going to put the index of the elementthat I want to change. So this eight is goingto be at index position one, and I can giveus a new value. So we can give this a valueof like 900. Now if I print out lucky numbers,one, you'll see that the value will have updated.So now we get the value of 900, instead ofjust getting the value of eight. So I'm ableto update these, I can really, you know, doanything that I could do with a normal variablewith each one of these individual values.And that's pretty cool. So in addition tocreating a, an array of integers, I couldalso create like an array of strings. So whydon't we do that I'm gonna make an array ofstrings. And I'm just going to call this friends.So this will be like a list of maybe my friendsor something. And I'm going to show you guysanother way that we can create an array likethis. So you'll see up here right away, Iwas giving this array A bunch of value. Soright off the bat, when I created it, I waspopulating this array with a bunch of information.But a lot of times when you create arraysin C sharp, you're not going to know exactlywhat elements you want to put inside of them.So if you don't know exactly what elementsneed to go in here, upfront, we can just createan empty array. So I can actually just say,a string friends, and I'm just going to setthis equal to new string. And then I'm goingto type in open and close square bracket.And inside of these square brackets, I needto put a number and this number is going totell a C sharp, how many elements we wantthis array to be able to hold. So if we createan array like this, and we don't give it elementslike we did up here, we still need to tellC sharp how many elements this array can hold,we need to basically tell C sharp, how bigwe want to make the array. So over here, ifI put 10 like that, that means that this friendsarray is going to be able to hold 10 values.If I put three, that means the friends arrayis going to be able to hold three values.So why don't we put five and down here, whatI can do is I can populate this array withinformation. So I could say like friends,zero is equal to and then I could type outthe name of a friend. So I could say like,Jim, and then I could do the same thing forthe other one. So I could say like friends,one is equal to Kelly, etc. So I could dothat for each element inside of this arrayand individually populate it. And this isactually going to come in handy in a lot ofsituations. And as we go forward in the course,I'm going to show you guys how we can do somethinglike that in a future tutorial. But for now,just know that this is another way that wecan create an array. Alright, so really, thatis the basics of using arrays. Arrays areextremely simple, but they're extremely powerful.It's essentially just a type of containermuch like a variable. But unlike a variable,it can store multiple pieces of information.And again, all of those pieces of informationneed to be of the same type, just like wehave up here. In this tutorial, I'm goingto talk to you guys about methods in C sharp.Now a method is basically just a little blockof code where we can perform a specific task.So a lot of times when you're writing programsin C sharp, you'll have like a few lines ofcode, maybe like five or 10 lines, which areperforming a specific task, like the wholeidea of having those lines in the programis that they're going to do a certain thing.So what we can actually do is we can createsomething called a method, which will allowus to take all that code and put it into itsown little container. And then we want toexecute it and we want to perform the task,that code is going to carry out, we can justcall that method, and we'll be able to reuseit in different spots in our program. So I'mgonna show you guys exactly how to createa method. And we're going to talk exactlyabout what it does and how they're useful.So what I want to do in this tutorial is Iwant to create a method, which is going tosay hi to the user. So the task of this methodis going to be to say hi to whoever is usingthe program. So what I want to do when I createa new method is I actually want to come downout here outside of these curly brackets.So believe it or not this line of code uphere where it says static void Main, thisis actually a method inside of our program.So like I said, a method is just a container,or it's sort of like a block where we canput code that's going to perform a specifictask. And this main method is very special,because this is the method that gets executedwhen we run our program. So any code thatI typed down here in this main method getsexecuted when I run my program. But in additionto writing this main method, we can also defineother methods that are going to work a littlebit differently. But it's the same idea, we'reencapsulating a bunch of code inside of itsown little container. So in order to createa new method, I want to first go outside ofthis main method. So this main method is allthe code that I have highlighted, you cansee it's delineated with this open and closedcurly bracket. So I'm going to come down herebelow this. And we can actually create a newmethod. So when I create my method, I needto tell C sharp a couple of different things.And the first thing we need to do is, saya keyword static. And I'm actually going totalk a lot more about what static means inlater tutorials. And as of right now, it'sreally not super important as to what thisis doing. Again, I will explain what thisis. But for now just know that we have toput static here, if we're going to put ourmethod alongside this main method. After Isay static, I need to specify something calleda return type. Now, these methods are awesome,because they can perform specific tasks forus. And one of the things they can do is theycan actually give us back information. Soif I was to run one of these methods, it canactually give information back to me. Andwe'll see how to do that. We're going to talkmore about return types in the next tutorial.But for now, I'm just going to say void, andthat basically means that this method isn'tgoing to return any information. So this iskind of like the simplest method that we cancreate. Alright, so after I say void, I wantto give this method a name. Now remember,methods are generally going to be performinga specific task. So you want to name the methodbased off of the task that it's performing.Our method in this tutorial is basically justgoing to say hi to the user. So I'm just goingto call this Say hi. And generally in C sharp,when we're creating a method, we're goingto create it using a capital letter for thename. So you can see I named it just likethat you can also see up here, main was namedwith a capital letter. And that's just a namingconvention, that's not necessary. But a lotof people are going to do that, then whatwe want to put in here is an open and closeparentheses, and then an open and closed curlybracket over there. And I'm just going togo ahead and indent in for into this curlybracket. Any code that we put inside of thesetwo curly brackets is going to be consideredpart of the method. So any code that we putin here will be run when we call our method.So I can essentially write all the code inhere to perform the task that the method isdesigned to carry out. Remember, this methodis just going to say hi to the user. So Ican basically just print something onto thescreen, I'll say console dot write line. Andwhy don't we just come over here and say,Hello, user, our method down here has oneline of code and methods can have as manylines of code as you want. I mean, you canhave, I think most methods have anywhere fromfive to 10 lines of code. But you can havemore or less than that, it doesn't reallymatter. In my case, though, I just have avery simple method. So it's going to be oneline of code. Alright, so now what I wantto do is go ahead and run my program, andwe'll see what happens. So I'm just goingto click this start button. And you'll seeover here, nothing got printed out. So eventhough we created our new method, and we puta line of code inside this method, it didn'texecute this line of code. In other words,this line of code never got executed by Csharp. Here's the reason. When we create amethod, this code isn't going to get run automatically,only the code that's inside of this main methodis going to get run when we run our program.So because this code wasn't inside of thismain method, it didn't get run. Now, if Iwant to execute all of the code inside ofthis, say hi function, I can actually do somethingcalled the calling it. So I can call thismethod. Basically, what that means is C sharpis going to go over to the method executeall the code inside of it. So the way I cancall the method is just by typing on its name,I can just say, say hi. And I can make anopen and close parentheses. And then now weshould be able to execute this code. So whenI run my program, now, you'll see we're printingout Hello, user, so the code inside the methodgot executed. Now, essentially, what's happeningis, whenever C sharp sees this line of code,what it does is, it jumps over, it goes overto this, say hi method. And it's going togo through and execute all of the code insideof there, then when it's done executing thecode inside of here, it's going to come backand it's going to move on to the next lineof code in the main method. That's essentiallywhat's happening. So this is extremely useful.And there's going to be a lot of circumstanceswhere you're going to want to have methodsthat are doing different things. And you'regoing to want to have all of that code insideof its own single container. But this is reallyjust scratching the surface of what we cando with these methods. And I want to showyou guys another thing we can do, we can actuallygive these methods information inside of thisSay hi function, I could actually specifythat this Say hi function should take in someinformation. And this is what we would callparameters or arguments. And a parameter isbasically just a value that gets passed intoa method. So it's the value that we wouldgive to this method. And then it can use thatvalue to perform its task better or do something.And the way that we can specify a parameteris just by coming in here and enter the openand close parentheses. And I can just basicallyspecify what type of information I want toaccept. So let's say that instead of sayinghello, user, we wanted this method to sayhi to a particular person, well, over here,I could specify string name. And now whenI write out this line, string name, I'm basicallysaying that the Say hi method needs to takeas a parameter as an argument, one value,which is going to be a name, then what I cando is I can come down here and I can printout Hello, name, you'll see we're gettingan error up here, when we're calling thismethod. That's because I didn't include aname when I called it. So now whenever I callthis method, I have to pass it a string. SoI'm going to pass it a string Mike. And essentially,what's going to happen is this string Mike,that I passed, this method is going to getstored inside of this string variable insideof this name variable. And then I'm just goingto print it out. So now, we should be printingout Hello, Mike. And you can see we get thatright there. So that's one cool way that wecan run these methods. And the other coolthing about methods is that I can call thiscode as many times as I want. And so I cancall it again and again, and each time passin a different name. So we'll pass in Mike,john, and Tom. And now each time we call this,the method is going to do something slightlydifferent. So it's going to say hi to someonedifferent. So now it's saying, whoops. Nowit's saying hello, Mike. Hello, john. Hello,Tom. So really, what we're doing is we'reable to write this code in one place, andthen we're able to reuse it continually insideof our program. And that's another reasonwhy methods are awesome. In addition to justpassing in one parameter, we could also specifythat this should take two parameters. So insteadof just a name, why don't we also pass inan integer age. And then down here, we canadd the agent so I can say hello, name youare and then we'll just print out the age.So now when I call these methods up here,you'll see we're getting more errors, becauseI have to give these values. So I can saylike 3356 and 12. And now when I run my program,it's going to be able to handle that. So thismethod is now printing out both the name andthe age that we passed in. And really, youcan pass anything you want into these methods,you can pass strings and doubles. You caneven pass things like arrays, it doesn't reallymatter. You know, any value that you wantto work with, you can pass into here, as longas you can specify it over there. So that'skind of the basics of working with methods.Now I will say you'll hear most of the timepeople are going to call these methods you'llalso hear people refer to these as functions.methods and functions are essentially thesame thing. There is a small difference, justin the definition, but generally you can usethe word method and the word function interchangeably.And you'll hear a lot of people call thesefunctions. You also hear a lot of people callthem methods, but generally in C sharp likethe official term would be A method. So that'sreally why methods are useful, you can kindof see, you know, we were essentially ableto reuse all the code that we wrote down here.So I can reuse it and give it different informationand it'll do different things. Now, in thenext video, I'm going to talk to you guysabout this value over here, which is goingto be the return value. So in addition topassing information into methods, methodscan also pass information back to the callers,and we're going to talk about that in thenext tutorial. In this tutorial, I'm goingto show you guys how to use return statementsin C sharp methods. So in C sharp a methodis basically just a little block of code,which is designed to perform a specific task.And in the last tutorial, I showed you guyshow we could create a very simple method thatwould say hi to the user. In this tutorial,I want to show you guys how we can use anotherfeature of C sharp methods, which is the returnkeyword. And basically, what we can do isinside of these methods, we can return valuesback to the callers. So I'm gonna show youguys how this works. And we'll kind of getan idea of what this is and what it does.So down here in my program, you'll noticeI have my main method over here. And I'm actuallygoing to create another method. So I'm goingto come down here below the main method. AndI want to create a method which is going tocube a number. So when you cube a number,you basically take it to the third power.So two raised to the third power is the sameas two times two times two, right, so we wouldsay that this is two cubed. So what I wantto do is actually create a method that willtake as a parameter, so take as an argument,one number, and then it'll cube it. And it'llactually return that number back to the caller.So this is going to be kind of cool. So remember,whenever we're creating a method, we needto say, static. And like I said, I'm goingto explain what static is and what it doeslater in the tutorial. But for now, just knowthat whenever you're creating a method, herenext to this main method, because main issuch a special method, I'm also going to usethis static keyword for the new method thatI create. Then the next thing I need to tellC sharp is going to be the return type. Andin the last tutorial, we use this void returntype, which basically meant we weren't goingto return any information. But now what Iwant to do is I want to actually specify aparticular data type that we're going to return.So in our case, why don't we just say we'regoing to return an integer. So now what Iwant to do is give this method a name. SoI'm just going to say cube, so it's goingto be called cube. Because it's cubing a number,I want to make an open and close parenthesesand an open and close curly bracket. insideof this parentheses, what I want to do isspecify a parameter. So this cube method isgoing to take one parameter, and it's goingto be an integer, and we're just going tocall it num. So num is going to be the numberthat they pass in. And eventually, what we'regoing to want to do is we're going to wantto return to them the value of num cubed.So what I can do down here is I can make aninteger. And I'm just going to say and we'llcall it result, and I want to set result equalto the cube value of num. In order to getthat we can just say num times num times num.And so now this variable result is going tohave num times num times num stored in it.In other words, it's going to have the numcubed stored inside of it. Now what I wantto do is use a special keyword in C sharpcalled return. And whenever we put this keywordinside of a method, this is basically goingto tell the method that we want to returnan piece of information back to the caller.And also this return keyword is going to breakus out of the method. So over here, what Ican do is I can just say return results. SoI'm going to go ahead and return this resultvariable that we just created back to thecaller. Now let's go up here in our main methodand actually call this method. So what I wantto do is, I'm just going to call it so I'mgoing to say cube, and I'll pass in a numberlet's pass in five. So now I'm going to goahead and run my program and we'll see whathappens. So you'll see my program ran. ButI mean, nothing really happened, right? Therewas no output there really, you know, therewas no errors, but really nothing happened.Here's the thing, though, if I was to comeover here and say console dot write line,if I printed out this method, in other words,if I printed out calling this method, you'llsee we're actually going to print out resultwe're actually going to print out the valueof cubing these numbers. So over here, I justsaid console dot write line. And inside ofhere, I'm printing out cube five. Now whenI run my program, you'll see we're printingout 125. Basically what happened was whenI use this return keyword down here, thatreturned the value back over to this method.So then when I called the method it was actuallyGiven the value of 125, and that is extremelyuseful. And that's basically a way that wecan get a piece of information back from amethod. Just to further illustrate this point,I want to create another example. So downhere, I'm going to make an integer. And I'mjust going to call it cube number, and I'mgoing to set it equal to cube five. So I'mactually setting this variable equal to cubefive. Now I can print out cube number, andyou'll see we're going to get that value 125back. And so that's essentially what we'reable to do, we're able to return a value backfrom this method, in addition to returningan integer, we could return anything. So ifI wanted, I could return a string, or a double.Or I could even return like an array of doubles,right, something like that. So you can reallyreturn any value that you want back from thesemethods. But returning information can beextremely useful. And you're definitely goingto want to use it inside of your C sharp methods.In this tutorial, I'm going to talk to youguys about if statements in C sharp, an ifstatement is basically a special structurein our program, which will allow our programto respond to different situations. So essentially,with if statements, our programs can becomesmarter. And I want to show you guys someexamples of if statements, and we're goingto kind of look at how we can create and useif statements in our programs. Now over here,I have this little text file open. And oneof the cool things about if statements isthat as human beings, we encounter them everysingle day. So over here, I have some examplesof if statements that you might see on a dailybasis. So up here, it says, I wake up, ifI'm hungry, I eat breakfast. So this is anexample of an if statement, essentially, anif statement has two parts, it has a condition,which is right here. And then it has an actionthat gets executed when the condition is true.So our condition up here is if I'm hungry.Now this condition is either true or false.It can only have two possible values trueor false. You're either hungry, or you'renot. If you are hungry. In other words, ifthis condition is true up here, then you'regoing to eat breakfast. But if you're not,if this condition is false, then you're justgoing to move on. And that is the essenceof an if statement, we check a condition.If the condition is true, then we'll performan action. If the condition is false, thenwe'll move on and we won't perform that action.So just like you're able to make a decisionabout whether or not you're hungry, and whetheror not you should eat breakfast, we can usethese in our programs to do the same thingto make decisions. And there's another onedown here it says I look at my phone, if it'sabout to die, I charge it. So again, thisis a condition, it's either true or false.If it's true, if your phone is about to die,then you charge it. Otherwise, we're justgoing to move on. Here's a little bit of amore complex if statement, it says I leavemy house. If it's cloudy, I bring an umbrella.So again, here's our condition. If it's true,then we're going to bring the umbrella. Ifit's false, though, now we're going to dosomething else. So up here, when the conditionwas false, we just moved on. But now, if thiscondition is false, otherwise, we're goingto bring our sunglasses, so we're going todo something else. And these are just somebasic if statements. But I just kind of wantedto give you guys an idea of what these werebefore we implement them in our programs.So we can do essentially the same thing. Butwe can allow our programs to make decisions.So when certain conditions are true, we cando certain things. And if they're false, thenwe can do other things. So let's go back overto our program dot C sharp. And you'll seedown here I'm just in my main method, andI'm going to show you guys how we can usesome if statements. So before we do any fstatements, I'm actually going to create avariable. So this is going to be a booleanvariable, and I'm just going to call it ismale. And this variable is going to tell uswhether or not somebody is a male. So I'ma male. So I'm going to set this equal totrue. So now we have this Boolean variableis male, and it has a value of true. Now whatI want to do is I want to create an if statement.And we can actually create an if statementand based off of this is male variable. Solet's say that we have this variable in ourprogram, we're working with it. And we wantto do something when the person is male. Soinside of our program when the person's male,when this variable is true, we want to beable to do something, I can use an if statementto check that. I can come down here and sayif and I'm gonna make an open and close parentheses,and an open and closed curly bracket. Andthis is sort of the general outline of anif statement in our program. Now, inside ofthis parentheses, I want to specify a condition.So just like over in that text file, we hadsome conditions like if I'm hungry, or ifmy phone's about to die. Inside of these parentheses,we want to specify a condition. Now this conditionIt needs to be a true or a false value, right?If I'm hungry, that was our condition beforethat's true or false, right, it can only haveone of two values. If my phone's about todie is true or false, it can only have oneof two values. So inside of this parentheses,we need to put a condition which is basicallyjust going to be a true or a false value.So in my case, I want to check to see if theperson is male. So I can say, if is male,and if this variable is true, then we're goingto be able to execute the code that we putdown here. So why don't we just write outconsole dot write line, and we'll just writeout you are male. So we're writing out consoledot write line, if the variable is male isequal to true. So let's go ahead and run thisprogram. And you'll see over here, it's printingout you are male. So our program was smartenough to determine whether or not someonewas male. If I was to set this equal to false,and now I went to run my program, when I runthe program, you'll notice that nothing isgonna get printed out because the variablewas false. So this line of code down hereonly gets executed when this condition uphere in these parentheses, is true. So that'show we can use a basic if statement. But let'ssay that when is male was false, we wantedto do something else. So let's say even ifthis variable was false, we wanted to tryand do something else. So I can actually useanother keyword in C sharp, which is calledelse. So I can say else and open and closecurly bracket. And then down here, we canwrite out another line of code. So I'm actuallyjust going to copy this guy and down here,and we're going to write out a you are notmale. So when they are male, we'll tell themthat and when they're not mail when his mailis false, we'll also tell them that so hismail is false right now. And it should tellus that so it should tell us you are not male.Essentially, what we've done now is we'vecreated a program that is able to respondto the value of a variable. So this programcan respond to this variable, right? If hismail is true, then we're going to print outyour mail. If his mail is false, then we'regoing to print out you are not mail. So ourprogram is smart, our program can adapt andadjust what it's doing, depending on the valueof a variable. And therein lies the essenceof if statements, if statements allow ourprograms to make decisions and to do differentthings, when different conditions are met.But this is a very simple if statement. Infact, this is probably like the simplest ifelse statement that we can write, I'm goingto make this a little bit more complex. Andwe're gonna go ahead and we're going to createanother variable. So I'm gonna come up hereand make another Boolean, and I'm just goingto call it is tall. And this is tall variable,again, is going to store a true or false value.So why don't we set both of these equal totrue, just to start off, so this is tall variableis going to tell us whether or not someoneis tall. So this will determine if they'relike tall or short. And down here, let's saythat instead of just checking to see if theyare male, we also wanted to check to see ifthey're tall. So I can say if is male. AndI can actually use another operator in C sharp,and it's called the AND operator. So I cansay, two ampersands, like this. And this standsfor and, and basically, when we use this andoperator, it allows me to write two conditionsin the same condition block. So it allowsme to not only check to see if they're male,but I could also check to see if they're tall.So now this is saying if is male, and is tall.So now, not only does izmail have to be true,but is tall also has to be true for this wholething to be true. So if one of these guyswas false, then this whole thing would befalse. So now I'm down here, I could say youare a tall male, right, and then down here,instead of saying you are not male, I caninstead say you are either not male or nottall or both, right, because if this codegets executed, it means one or both of theconditions up here is false. So let me demonstratethis. You'll see over here, both of theseare set to true. And when I run my program,it's going to be able to respond to that.So you'll see it says you are a tall male,because both of those were true. But let'ssay I set one of these to false, so I sethis male equal to false. Well now becauseone of these guys is false, this whole thingis going to be false. So we're going to printthis out down here. So now when I run theprogram, you will see it's printing out youare either not male or not tall or both. Soit's able to respond to those two variablesin our program. In addition to using thisand operator we can also use another operatorWhich is called for, and or does the samething as and except it's a little bit differentso or will allow us to check two conditions.But this time, only one of these conditionshas to be true for this whole thing to betrue. So we would read this as if is male,or is tall. So they either have to be male,or they have to be tall, or they can be both.And then we'll be able to execute this coderight here. But if both of these guys arefalse, then we're going to go down here andexecute this code. So let me just demonstratethis really quick. And I'm not going to botherchanging the text here, you guys kind of hopefullyget what's going on. So even though falseand true, are both up here. So even thoughone of these guys is false, we're still goingto be able to print out You are a tall male.But if I was to make both of these false,now we're going to end up printing out youare either not male or not tall, or both,which again, I realize isn't the right textfor that, but you can just kind of understandwhat's going on. So it says you're eithernot male or not tall, or both. So that's thedifference between and and or when we use.And here, both of these conditions have tobe true. So both of these variables wouldhave to be true for this whole thing to betrue. And for us to execute that code, whenwe use or only one of them has to be true.So this could be false, or this could be false,but one of them has to be true for the wholething to be true. And that's really the difference.So I'm going to turn this back to and andI want to show you guys some other stuff wecan do. So right now we're able to check thecondition where they're male, and they'retall. But there's also a couple of differentscenarios. In addition to that, for example,let's say that they're male, but they're nottall. Well, what if we wanted to do somethingwhen they were male, but they were not tall.So if they're like a short male, I can actuallyuse another keyword or another reserved wordin C sharp, which is called else F. And Ican just type out alsef, like this, I canmake an open and close parentheses and anopen and close curly bracket. And then I'mjust going to make a new line. So essentially,what I did here was I added in elsif. Andthen you can see this else basically goesafter it. When I use LS if it allows me tocheck another condition. So if this conditionup here is false, I can actually come downhere and check another condition. So we wantedto check to see if they were male, and theywere not tall. So I could say else if is male.And now I need to figure out how I can specifyand not tall. So remember, this variable istall will tell us if they're tall or not.If I wanted to find out if they're not tall,I could just say exclamation point is tall.And this is going to read as not tall, notis tall. This exclamation point here is what'sknown as the negation operator. And this willbasically negate the condition. So over hereI have is tall. If this was true, then whenI put this exclamation point here, it's goingto make it false. If this was false, whenI put this exclamation point here, it's goingto make it true. So this whole thing is goingto be true when the person is not tall. Andso now this is essentially checking to seeif they're male, and they're not tall. Sodown here, we can write another message. SoI can basically say like you are a short male,because they're male, but they're not tall.And finally, I'm going to make one more elsif.So I'm just going to come down here. And there'sone more thing that we want to check. So Ialso want to check to see if they're tall,but they're not male. Right. So over here,we're checking if they're male, and they'retall. Over here, we're checking to see ifthey're male, and they're not tall, down here,I want to check to see if they're not male.And they are tall. So this is saying elseif not male, and is tall. So down here, wecan put another little message. And I'm justgoing to basically say like you are not amale, but you are tall. So this is essentiallyjust saying exactly what it is you're notmale, but you are tall. And then down herefor this else. Remember, this code now isonly going to get executed when none of theseconditions up here are true. So now down here,we can just say you are not male and not tall.Alright, so let me walk you guys through thisone more time. Up here, I'm saying if is maleand is tall. So this condition is only goingto be true when both of these are true. Andthen if this is true, we're going to comedown here and execute this code, we're goingto say you are a tall male. But if this isfalse, we're going to come down here to thiselsif. And we're going to check another condition.So only when this is false, or we're goingto check this condition down here. And we'rebasically going to check to see if they'remale, and they're not tall, and I'm usingthis negation operator here. And if that'strue, then we're going to tell them that we'regoing to print that out. Then we're goingto check to see if they're not missing. Andthey're tall. And we'll print out a messagefor that. And then finally, we'll say youare not male and not tall. So let's go aheadand run our program. And you'll see both ofthese guys, we're going to be set to trueinitially. And we'll try all these differentcombinations. So both of them are set to true,I'm going to run the program, and it saysyou are a tall male. So our program was smartenough to be able to respond to the valueof these two variables. So now let's set hismale equal to false. So I'm going to comedown here, and we'll just say false. And now,essentially, this is going to be able to respond,so I can run my program now. And you'll seeit's printing out, you are not male, but youare tall. So it was able to respond to thatdifferent value. Now we'll set his male backequal to true, and we'll set his tall equalto false. And now we should get a appropriateresponse. So it says you are a short male.And finally, if these are both equal to false,then again, the program's going to be ableto respond to that. So it's gonna say, youare not male, and not tall, awesome. So essentially,what we did with these if statements was weallowed our program to respond to differentvalues, right, our program was able to makedecisions based off the information that itwas given. And this is really just scratchingthe surface of if statements. You'll see overhere, we're using these Boolean variables,right. But there's actually another way thatwe can specify these conditions, and it'susing something called comparisons. And inthe next tutorial, I'm going to talk to youguys all about comparisons about how to usethem. And it's basically just another waythat these if statements can come in handy.In this tutorial, I'm going to talk to youguys some more about if statements, more specifically,we're gonna be talking about comparisons.So inside of an if statement, we can actuallycompare two values. And depending on you know,the result of the comparison, we can do differentthings, this is going to be kind of cool.And essentially, what I want to do in thistutorial is I want to build a method. Andthis method is basically going to be a maxmethod. So the max method, if you're not familiar,is basically a method where we can give ittwo numbers, and it'll tell us which one isbigger. So we're going to write a method thattakes two parameters as input, number one,and number two, and then we'll basically beable to return whichever is bigger. So I'mgoing to go down here, and I'm going to gobelow this main method, and we're going tocreate another method. So I'm just going tosay static. And I'm going to want this toreturn an integer. So why don't we just saythat it's going to return an integer, andI'm going to call it get max. And then I'mgoing to make an open and close parenthesesand open and close curly bracket. So get Maxis going to take one or two parameters. Sowe're going to take in an integer num one,and then we're also going to take anotherinteger, num, two, basically, the job of thismethod is to figure out which of these twonumbers is bigger, and then return it to thecaller. So let's go ahead and set this up,I'm actually going to create a variable. SoI'm just going to make an integer I'll callit result. And I'm not actually going to givethis a value yet. So we're going to end upgiving this value inside of the method. Andthen down here, I'm going to return results,I'm just going to return this variable. Andinside of this method, now our goal is tofigure out which number is bigger, right.So inside of this method, we don't know ifnum one is bigger or num two is bigger, wehave no idea. But all we know is that we havetwo numbers here that we can work with. Sowhat we want to do is use an if statementand an if statement will allow us to do somethingwhen a certain condition is true, and do somethingelse when a certain condition is false. SoI'm going to make an if statement, I'm justgoing to say if and I'm gonna make an openand close parentheses and open and close curlybracket. So this is like the sort of outlinethe structure for our if statement. Now insideof these parentheses, I need to put a conditionand remember a condition is a true or falsevalue. In the previous tutorial, we were usingBooleans as our condition. So I had a Booleanlike is male and another one is tall. Andwe use that as the conditions for if statements.But here's the thing, we don't necessarilyhave any Booleans to work with, right? Allwe can work with here are these two integers.So what I can do is I can actually use somethingcalled a comparison. So I can compare thetwo numbers. So I can actually say like ifnum one is greater than num, two. And essentiallywhat I'm doing here is I'm comparing the twovalues. But remember, inside of these parentheses,we need a condition we need a true or a falsevalue. But actually the cool thing is thatwhen when we do this comparison, this is goingto resolve down to a true or false value.Right? So num one is either going to be greaterthan num two or it's not. There's only twopossible scenarios with this comparison. Righteither it's true And num one is greater thannum two or it's false. And num two is greaterthan or equal to num one, right. So really,this gets resolved down to a true or a falsevalue anyway, so these comparisons can besuper useful inside of our parentheses. Nowinside of this actual f block, if num oneis indeed greater than num two, then we canjust set result equal to num one. And thenI'm going to make an else statement down here.And I'll just say else. And I'm just goingto say, result is equal to num two. So ifnum, one's greater than num, two, then we'llmake result num one. Otherwise, we'll makeit num two. And then down here, we're justreturning result. So this method is basicallydone, we have everything that we need, weshould be able to figure out which numberis bigger. So let's go back up here to ourmain method. And I'm going to call this andI'm actually going to print out the answer.So I'm just going to say, console dot writeline. And then inside of these parentheses,we're going to call it so I'll just say getmax. And why don't we pass this to and 10.So ideally, we're going to get a 10 back,because 10 is the bigger number. So let'sgo ahead and run this program. And you'llsee we're getting that 10 back, no problem.So let's now see if it's gonna work when thefirst numbers the bigger one, and hopefullyit does, so we should get 20, which we do.So this method is working out. And you cansee, we're able to use this comparison inorder to figure it out. So that's awesome.And this is pretty cool. But I'm going toget rid of this, let's up the ante a littlebit, let's make this a little bit more difficult.Let's say instead of two numbers, we wantedto be able to compare the three numbers. Sowe wanted this max function to be able totell us the maximum of three separate numbers.Well, in here, I can just specify anotherparameter. So I can say num three. And nowdown here, not only do we have to figure outtwo of them, we have to figure out three ofthem. So of these three numbers, which oneis bigger. Now we're going to want to useanother if statement. So I'm going to go aheadand this time, I'll make that same if statement,essentially. And now we need a condition.So not only do we need to check to see ifnum one is greater than num two, but we alsohave to check to see if it's greater thannum three. So I'm going to say if num oneis greater than or equal to num, two. Andso I'm using this and operator num one isgreater than or equal to num three, then downhere, we can set result equal to num one becauseif no one's bigger than num, two, and it'salso bigger than num three, then we know it'sthe biggest one, right, so we can just goahead and return that. But let's say thatthis isn't the case, I want to do anotherone. So I'm going to say else if and we'llmake a another condition down here. So I'mbasically just going to say else if num twois greater than or equal to num one, and numbertwo is greater than or equal to num three.Right. So if num two is bigger than num one,and it's bigger than num three, then num twos,the biggest. So we'll say result is equalto number two. Finally, then we can just sayELSE, AND down here we can specify the else.So I'm just going to go ahead and set resultequal to num three. Because if num one's notthe biggest, and remember, we check that uphere and num twos, not the biggest, whichwe checked down here, then num three is goingto be the biggest. So let's go ahead and testthis out. So now we need to include anothernumber. So I'm going to put like a four inhere. So we should get back this 20 becausethat's the biggest number. And you can seewe do, let's try it with the other places.So let's make this last one here, we'll makethis a 40. So this is going to be the biggest.And we'll see if this works, which it does.So this get max method seems to be workingout pretty well. Now down here, you'll noticewhen I compare to the two numbers, I'm usingthese like greater than or equal to zero beforeI just use a greater than these are calledcomparison operators. And these comparisonoperators can be used to compare differentvalues. So I can use greater than, less than,greater than or equal to, less than or equalto, I can also use equal to, and this doubleEagles is special because it's going to allowus to compare these two numbers. So this isn'tused for assignment like down here we usea single equals for assignment so I assignedthe value of num one to result up here I'mcomparing the value so I'm basically checkingto see if the value of num one is equivalentor equal to the value of num two. And thenwe can also use one more which is going tobe not equals and this is going to be theopposite. So this will say num one not equalto num two. So that's essentially how we canuse comparisons. And you can also, in additionto numbers, you could also compare like characters.So I can compare like two characters, youknow, basically like that. And that's goingto work out just fine. So these comparisonsare extremely useful. And I would say thata lot of times when you're using if statements,you're going to be using comparisons justlike that. In this tutorial, I'm going toshow you guys how to build a four functioncalculator in C sharp. Now, if you've beenfollowing along with this course, you'll knowthat in the beginning of the course, we actuallycreated a very simple calculator. And essentially,the calculator would let the user enter intwo numbers. And it would take those numbersand sort of add them together and then printout the answer, right, it's very simple. Inthis tutorial, we're going to take that calculatorto the next level. So we're going to actuallyallow the user to enter in two numbers. Andthey're also going to be able to specify anoperator. So they'll be able to specify whetherwhether or not they want to add the numbers,subtract the numbers, multiply or divide thenumbers, so it's gonna be pretty cool. Andlet's go ahead and get into it. So the firstthing we want to do is we want to be ableto get all the information from the user.So I'm going to basically just going to beprinting out prompts, and then we'll be storingthe values that the user enters inside ofvariables. So the first thing I'll do is justprint out a prompt, basically prompting themto enter in some information, and actually,I'm just gonna use right instead of writeline. So I'll say, enter a number. And they'llenter their first number. And then what wewant to do is want to get that number andstore it inside of a variable. So let's storethis inside of a double. So I'm just goingto call this num one. And I'm just going toset it equal to console dot read line. Butremember, whenever we use console dot readline, this is going to give us a string back.So if I want to store this value inside ofa double over here, I'm actually going tohave to use something called convert. So I'mgoing to say convert.to, double, and I'm goingto place console dot read line inside of thismethods parentheses. So I'm going to passthis in as an argument as a parameter to theConvert to double method. That's essentiallywhat's happening there. And I'm basicallyjust going to copy this line. And I'm goingto paste it down here, because we're goingto do the same exact thing for the secondnumber. So I'm going to say num two is equalto convert to double console dot read line.So we're getting the first number and we'regetting the second number and we're storingin them in the num, one variable in the numtwo variable. Now one more thing I want todo is I want to get the operator. So I'm basicallygonna say I'm just gonna say console dot write.And over here, I'll just say, operator. Sothis is going to be like a plus sign a minussign, division, sign, multiplication, sign,etc. And then down here, we can just makethis a string. So I'm going to say stringop for operator is going to be equal to consoledot read line. So basically, what I'm doingis I'm getting the first number, I'm convertingit to a double, I'm getting the operator plusminus division, whatever, I'm getting thesecond number. So now at this point in myprogram, I should have all the informationthat I need. So the question becomes how canwe perform the operation? In other words,we have the two numbers, great, but how canwe figure out what the user entered in? Right?How do we figure out what Opie is tellingus to do, we can use an if statement. So I'mgoing to use an if statement, I'm just gonnasay if let me make an open and close parenthesesand open and closed, curly bracket. And downhere, we want to check a condition. So essentially,what I want to do is I want to check to seeif the operator is equal to a plus sign. SoI can say if op is equal to plus sign, right?If the operator is equal to a plus sign, thenwe know for a fact that they're trying toadd the numbers. And I'm actually just goingto print that out down here. So I can sayconsole, dot write, and we're basically justprint out num, one plus num two. And actually,I'm going to do write line here. Alright,so if it's a plus sign, then we're going tobe able to add the numbers. But what if it'snot a plus sign? Well, I want to check anothercondition here. So I'm going to say, elseif and we'll check another one. We basicallywant to check to see if the operator is equalto a minus sign. If the operator is equalto a minus sign, now we're going to do thesame thing we did up here. It's just thatwe're going to subtract the number. So I'mgoing to say num one minus num two. We cando the same thing for multiplication and division.So I'm going to go ahead and copy this codeand I'm just going to paste it down here.And down here. Instead of checking minus we'rejust going to check division and then if itis division, we're going to divide the numbers.And then finally, I'm going to check for multiplication.So I'm going to say Asterix for multiplicationand then num one times Number two. So we'reable to cover all four operations, right addition,subtraction, division and multiplication.Each time, whatever the user enters, we'regoing to perform the correct operation, right?This if statements, pretty simple. But let'ssay that the user enters in an operator that'snot equal to any of these guys up here, right?What if they enter in like a random characterlike a string of text? Well, we want to beable to throw an error message. So what Ican do is I can come down here and just sayelse. And then inside of this else block,I'm just gonna say, console dot write line.And I'm just going to print out like, invalid.operator. So this will basically tell themlike, Hey, you had an eight, you had an invalidoperator, like, That's not good. So now wehave our whole program. And we use our littleif else structure here to figure out whatwas stored inside of that op variable. Sowe figured out what the user wanted us todo. Let's go ahead and run this program. Andwe'll see how we did. Over here it says, entera number I'm gonna enter 10 and enter an operator,why don't we do addition, and enter anothernumber? Why don't we do like 5.5. So now whenI hit enter that if statement is going toexecute, and it's going to see that plus sign,and it's going to be able to add the numbers.So you see here, we get 15.5. So we successfullyadded the numbers together. Let's try a differentone, I want to do multiplication. So let'sdo 60 times 4.23. And we get 253. Yeah, thatseems about right. Alright, so let's try onemore. And we'll try to break it. So I'm basicallyjust going to enter a number 40. And now I'mgoing to enter in an invalid operator. SoI'm going to enter in like an H for the operator,and then we'll enter in a five. And now thisshould tell us invalid operator because theprogram didn't recognize that operator. Inother words, it wasn't able to handle that.So we threw our little error message. Andthat's essentially all we need to do to buildthis four function calculator. The magic isin the if statement. So we can use the ifstatement to figure out what calculation orwhat operation the user wanted to do. Andwe can just keep using all these differentassets in order to figure that out. So thisis extremely useful. And hopefully, you canfind a use for something like this and yourprograms. In this tutorial, I want to showyou guys how to use switch statements in Csharp. Now a switch statement is basicallyjust a special type of if statement wherewe can check a bunch of different conditionsreally easily. And there's, I'll be reallyclear in the example that I showed you guys.So let's go ahead and get started. Down here,my program, I just have a very simple programset up. And in this tutorial, I want to createa method. So we're actually going to createa method, which is going to convert numbersinto days of the week. So if I pass this methodis zero, it would give me back Sunday, becauseSunday is the first day of the week. If Ipass this a one, it would give me back a Monday,right? If I pass this a two, it would giveme back Tuesday, etc, right. So if I, youknow, it's basically going to map numbersto the specific day of the week that we'regoing to give it. And this is going to bea pretty cool method. So I'm going to comedown here and we're going to go ahead andwrite the method, I'm just going to say static.And this is going to return a string. So it'sgoing to return the name of the day of theweek. And I'm just going to call this getday. And this method is going to take oneparameter and it's going to be the day num.So I'm just going to call this day num. Sode nom is going to be like 0123456, etc, right?It's going to be a number. And we're goingto take that number and we're going to convertit into a day of the week, we're going toconvert it into a string, which would be theday of the week. So I'm going to create avariable over here, that's going to be a stringvariable. And I'm just going to call it dayname. And I'm not going to give it a valueand then down here, eventually Our goal isgoing to be able going to be to return dayname. So inside of our little method overhere inside of our method block, our goalis to populate this day name variable witha value right with the correct value, that'sgoing to correspond to the day num that getspassed in. Cool. So I'm going to show youguys how we can use a special structure inC sharp to do this, and it's called a switchstatement. So I'm going to set up my switchstatement, I'm just going to say switch, I'mgoing to make an open and closed parenthesesand open and close curly bracket. And downhere, we're going to be able to start writingour switch statement. Now, the switch, Davidneeds one piece of information inside of thisparentheses, and it basically needs a value.So the whole point of the switch statementis we're going to pass it a value and thenwe're going to check to see if that valueis equal to a bunch of different stuff. Anddepending on what it's equal to, we're goingto do different things. So this will be clearin a second. In here, I'm going to pass inde nom. Because if daenam is zero, I wantto do something if daenam is one, I want todo something else. If daenam is two, I wantto do something else. In other words, my goalis to figure out what the de nom is. And dependingon what it is, I'm going to do something inother words, I'm going to give this day namevariable a different value. Now down here,in the switch statement, we can make whatare called cases. So I can come down hereand I can just type out case. And over here,I can just type in a value. So I can say zerohere. And I'm going to make a colon down here,I'm basically just going to say day name isequal to Sunday. And I'm also going to say,break down here. So let's talk about whatthis is saying. Essentially, this line, thislittle block of code is saying that in thecase, that day, num is equal to zero, I wantto do this. So in the case that de nom hasa value of zero, we're going to do whateverI specify down here, essentially, what I'mdoing is I'm saying day name is going to beequal to Sunday. And I'm also saying break,and we're going to talk about break in onesecond. So now what I can do is I can createone of these cases for each of the possiblenumbers, right. So now instead of just makingone for zero, I'll make one for one. And thecase that day num is one, I'm going to sayday name is going to be equal to Monday, right?And then I get I'm going to say break. Andwe'll do this one more time, I'm going todo it for two. So in the case that day, numis equal to two. Now I'm going to say dayname is equal to Tuesday. And you'll noticehere I'm using this break statement. And thisis a special reserved word in C sharp, whichbasically says that we want to break out ofthe structure that we're currently in. Sowe're inside of this switch statement. Andessentially, what happens is with this switchstatement, it's going to look through allof these different cases. So it's going tosay okay, is it zero? Is it one is it two,but let's say that de nom is zero, right?So it says his case, zero, yes, we're goingto execute this, we're going to assign a valueof Sunday to daenam. If I don't put this breakstatement in here, then C sharp is going tokeep checking all of these cases after that,so it's not going to stop, it's going to keepchecking. So if you have a scenario whereyou want to be able to keep checking the othercases, even after one of them was true, thenyou can get rid of the break statement. ButI think in most cases, you'll probably justwant this break statement in there. Alright,so I've made one of these for Sunday, Mondayand Tuesday, I'm going to go off and makesome for the rest of the days of the week,and then we'll come back and check it out.Alright, so I went ahead and made one of thesefor every day of the week. You can see wehave Sunday, Monday, Tuesday, Wednesday, Thursday,Friday and Saturday. And this is a reallyeasy way to check all these different cases,right, I can just say case six day name, Saturdayexcetera. So we basically have our case statementset up, we have our switch statement set up.But here's the problem, let's say that theuser passes a value into this method, that'snot zero through six. Right? So this case,this switch statement can only handle values,zero through six. But what happens if someonepassed like a 102? there? Well, I can actuallyaccount for that. So down here, I can createsomething called a default, I can basicallyjust type out default, I can type a colon.And now down here, I can specify what I wantto do if none of these cases are true. SoI could come down here and I can basicallyjust say, de name, and we'll just set thisequal to invalid number, or why don't we sayinvalid day number. And this will basicallyact as like a error message. And then downhere, we're also going to need to say break.So this is essentially how we can accountfor any values that aren't included up hereas cases. So our function or our methods seemsto be done at this point. So let's go aheadand try it out. So remember, get day is goingto take one value, which is going to be anum. And let's go up here to our main method,and we'll try this out. So I'm actually justgoing to print out whatever we get. So I'mgonna say console dot write line. And I'mgoing to go ahead and print out get day andlet's pass this as zero. So I'm going to goahead and say get day zero. So hopefully,we should get Sunday back because Sunday ismapped to zero. And you'll see over here thatwe get Sunday back so let's try another one.Why don't we try four? And I think four isgoing to be Thursday. Yeah. So Thursday. Andlet's try one more. So I'm going to try aninvalid number. So let's put ad in here. Soif I say get day ad now we should get thaterror message which tells us that it's aninvalid day number. Yeah. So over here we'regetting that invalid day number So that'sbasically what we can do is switch statements.Now let me just point this out everythingthat you can do with switch statements youcould actually do with if statements. Thereason that we have switch statements thoughis because they make it a lot easier to doessentially what we're doing over here, youcould do with if statements, but it wouldbe a lot messier than this, and it would bea lot harder to manage. With switch statements,it's very clear, right, it's very clear what'sgoing on and what values are getting mappedto what code so switch statements are extremelyuseful, and you should definitely considerusing them in your C sharp programs. In thistutorial, I'm going to show you guys how touse while loops in C sharp. Now while loopis basically a programming structure thatallows us to loop over a specific block ofcode, while a certain condition is true. Basically,using while loops, we're able to keep doingsomething repeatedly while a condition istrue. And this can come in handy in a bunchof situations. And loops are extremely usefulin a programming language like C sharp. Solet's get started. I'm going to show you guyshow they work and how to use them. Basically,just to give you a general introduction intowhile loops, down here in my main method,I'm actually going to create one thing, andthis isn't going to be the while loop, I'mjust going to create a variable, it's goingto be an int, and I'm just going to call itindex, and I'm gonna set it equal to one.And we're gonna end up using this index variableinside of our loop. So now I want to createa while loop. So I'm just gonna say whileand I'm gonna make an open and close parenthesesand an open and close curly bracket. Now here'show while loops work up here in these parentheses,I'm going to specify a condition. So if you'refamiliar with if statements, you'll know thatwith an if statement, we have a condition,right, we check a condition. And if that conditionis true, then we execute the code inside ofthe if statement. Pretty simple. It's thesame concept with this while loop up herein this while loop, I'm going to specify acondition. And if this condition is true,I'm going to be able to execute all of thecode that goes down here in these curly brackets.The only thing is with a while loop, not onlyare we going to execute at one time, but we'regoing to keep continuously executing it untilthe condition up here in these parenthesesis false. So we're basically going to checkthis condition. If it's true, we'll executeall the code inside of these curly brackets.And then we'll come up with check the condition.Again, if it's still true, we'll come downand execute it again. So you're continuouslylooping through this code. So it's essentiallyan if statement, but you keep going untilthe condition is false. And over here, inthese parentheses, we need to specify ourcondition. So I'm going to make a conditionI'm just going to say while index is lessthan or equal to five. So as long as thisindex variable is less than or equal to five,I'm going to keep executing all the code downhere. And then down here, I'm basically justgoing to write a few lines of code. So I'mgoing to say console dot write line, and we'regoing to print out the value of index. Andthen down here, I'm going to increment thevalue of index. So I'm going to say indexplus plus. And remember, this plus plus basicallyjust adds one onto the index. So essentially,what's happening is, every time we go throughthis loop, I'm going to print out the valueof index, then I'm going to increment index,and then I'm going to go back here and checkthe condition again. So this is our basicwhile loop, I'm going to run the while loop,we'll see what happens. And then I'm goingto explain exactly what happens. So we canget a better idea of how this works. Let'sgo ahead and run the program. And you'll seeover here, I'm printing out one through five.And maybe you expected that maybe you didn't.But this is what we got. And I'm going togo ahead and explain exactly how this happened.Step by step. So the first thing we did uphere was we created this integer index andwe set it equal to one right now, then wecreated our while loop. So when C sharp goesto execute our program, it's first going tocreate this variable index, and it's goingto store one inside of there, then the nextthing it's going to do is check this condition.So the first thing before it executes anyof the code inside of the loop before it doesanything else, it's going to check this condition.So it's going to check to see if index isless than or equal to five, since index wasequal to one initially, that's going to betrue. So then C sharp is going to go down,it's going to execute this line. So it's goingto print out index onto the console, as youcan see over here, then it's going to incrementindex. So index is now going to be equal totwo, then C sharp is going to go all the wayback up to this condition and check it again.So before C sharp is going to execute thatcode a second time, it needs to check thecondition again. So now index is equal totwo and two is less than or equal to five.So C sharp is going to come down here, it'sgoing to print out two, as you can see rightthere, and it's going to increment index,then it goes all the way back up and checksthe condition again, right? So every singletime we execute all that code before it'sgoing to execute it again it goes back upand checks the condition. All right, eventuallyWe're going to get to a point where indexis going to be equal to five, and we printedout five over here, then we're going to incrementit to six, C sharp is going to come up here,and it's going to check is six less than orequal to five, and then the condition is goingto be false. So we're going to break out ofthe while loop just like that. And that'sessentially how we can use these wild loops.So it's very simple, right, you specify acondition, and you're going to keep loopingthrough the loop as long as that conditionis true, easy enough. Now, I do want to warnyou guys of something, there is a possibilityof something called an infinite loop. Andan infinite loop is a situation where thiscondition up here never becomes false. Sofor example, if I was to get rid of this indexplus plus, now this condition up here, indexless than or equal to five, this is alwaysgoing to be true. Because we're never modifyingthe value of index when we were incrementing.It, eventually we would increment it enoughto get to five. But since we're not incrementingit anymore, we're just going to loop infinitely.So let me show you guys what happens whenI do this. When I run my program, you'll seeover here that I'm just constantly printingout one, I mean, this, it's literally justprinting out one as fast as it can. And it'sgoing to do this forever. If I let it it'lldo this infinitely, because it's never toldthat it needs to stop. In other words, thiscondition up here is never false. And so that'swhy we have an infinite loop. And that's probablygoing to happen to you, as you play aroundwith loops. Everyone's had an infinite loopbefore. And in most cases, you're going towant to avoid them, although there are somespecial cases where you're actually goingto want infinite loops. So that's sort ofthe basics of while loops. It's very simple,right? We have a condition up here, as longas that condition is true, we're gonna keepexecuting the code down here. And every singletime we go through the loop, we check thatcondition. Again, I want to show you guysone more thing. And there's actually anothertype of loop that we can use, which is similarto a while loop, it's called a do while loop.And in order for me to kind of illustratewhat this is doing, I want to show you guysan example. So if I came up here and set indexequal to six, let's talk about what's goingto happen. So if index is equal to six, right,the first thing that my program does withthis while loop is it checks this condition.So the first thing before it executes anyof this code before it's allowed to even touchthat code, it checks this condition. So sinceindex is equal to six, and this conditionis getting checked, before we execute thecode, this code is never going to execute,because six is not less than or equal to five,this condition is false. So we're never goingto execute this code. So if I run my program,you guys will see that nothing gets printedout, right, we don't execute any of the codeinside that while loop. But there's actuallyanother type of loop, which is essentiallythe opposite of a while loop. And I'm goingto show you guys that. So I'm going to basicallygoing to take this while loop declarationup here, I'm going to throw it down here.And I'm going to make sure I put a semicolonafter it. And then up here, instead of sayingwhile I'm going to say do. And so now we haveanother type of loop, which is a do whileloop. And the difference between a do whileloop and a while loop is that a do while loopwill execute the code inside of the loop beforeit checks the condition. So now even thoughindex is equal to six, we're still going tobe able to execute this loop one time beforewe look at the condition, right, so it's basicallygoing to execute all this code, then it'sgoing to look at the condition, it's goingto figure out that it's false. And it's goingto go ahead and break out of this. So I'mgoing to show you guys how we can do this.And I'm just gonna run my program. And you'llsee that even though this condition was false,even though six is not less than or equalto five, we were still able to print it outone time, because in a do while loop, youexecute the code inside the loop first, andthen you check the condition. So that's basicallyanother type of loop that we can use. Anddo wire loops definitely come in handy. Andthere's a lot of situations where you wantto use them. Although I would say that bya huge majority, while loops are more useful.But do while loops are also awesome. So that'skind of the basics of while loops, and dowhile loops. And this is really just the basicsof looping. In general, there's a lot of situationswhen we're programming, we're going to wantto continually do the same thing until a certaincondition is false. And that kind of givesyou an overview of how it works. In this tutorial,I'm going to show you guys how to build aguessing game in C sharp. Now this is goingto be a very basic guessing game. Essentially,we're going to define a secret word. And thenthe user is going to have to try and guessthat word. And we're going to keep askingthe user to try and guess it until they getit right. So this is going to be kind of cool.And I'm going to show you guys how we canuse some of the stuff that we've learned inthis course. So far things like loops, andif statements and variables, we're going touse all of them together to create this coolgame. So let's start creating the game. Remember,this is going to be a guessing game. So thefirst thing we want to do is Come up witha word that the user is going to have to guess.So I'm going to create a variable and it'sjust going to be a string. And I'm just goingto call it secret word. And the secret word,why don't we just give it a value, we'll setit equal to draft. So draft is going to bethe secret word. And the user's goal for ourgame is going to be to try and guess thatsecret word. Now I want to create one morevariable. And we're actually going to callthis one guests. So this is going to be anotherstring. And I'm just going to say it's calledguests. And why don't we just set it equalto this empty string over here, so I'm notreally giving this a value yet. Alright, sonow we have our secret word. And we also haveour guests. And what I want to do is, I wantto be able to keep prompting the user to guessthe word until they get it correctly. So anytimein C sharp that we want to keep doing somethingrepeatedly until a certain condition is false,we're going to use a while loop. So I'm goingto go ahead and create a while loop. And I'mjust gonna make an open and close parenthesesopen and close curly bracket. And there'sreally two things to this while loop, thefirst thing is going to be a condition. Andthe second thing is going to be the code thatwe want to continually execute. So let's thinkthis through what condition do we want toput up here? Well, basically, we want to keeplooping, while the guests is not equal tothe secret word. In other words, as long asthe guest the user guesses isn't equal towhat the secret word is, we want to keep loopingand keep asking them to guess. So down here,what I want to do is keep prompting them toguess. So I'm basically just gonna say, consoledot write, and I'll write out to the screena prompt, I'll say, enter guests. And thennow that we've prompted them to enter theguest, what I want to do is I want to takewhatever they entered, store it inside ofthis guests variable. And that way, we cankeep checking it every time we go throughthis a loop. So down here, I'm basically justgoing to say guess, is equal to console dotread line. So I'm going to go ahead and readthe line of text that the user enters, basicallyjust read whatever word they entered in andstore it inside of this guest variable. Soessentially, what's happening now is, everytime we go through the loop, we're promptingthe user to guess the word, and we're storingwhatever they guess, inside of this guestvariable, then we're going to go up here,and we're going to check to see if it's equalto the secret word. If it's not equal to thesecret word, then we're going to go throughand ask them again. But if it is equal tothe secret word, then we're gonna go aheadand break out of the loop. And then down here,we can just print out a success message. SoI can just print out console dot write, andI'll just print out you win. So this is ourprogram, it's actually a pretty easy program.And I do just want to point out that in additionto using a while loop, we also could haveused a do while loop in order to write thisprogram. So if you want a little challenge,and you want to try and challenge yourself,go ahead and try to write this with a do whileloop instead of a while loop. And if you needto figure out what do while loops are justcheck out the previous tutorial, I explainedwhat they were. But for our case, I'm justdoing it with a simple while loop just tokeep it as straightforward as possible. Butlike I said, if you want a challenge, tryit with a do while loop. So let's see if wecan run our program. Believe it or not, thisis actually all the code that we need forthis guessing game. So I'm going to go aheadand run the program. Now you'll see over here,it says enter guests, so I'm just going totype in some random text. And you'll noticethat because this text didn't match the secretword draft, it's asking me to enter again.So I'm going to keep entering and I can keepentering essentially infinitely many times.And it's going to keep prompting me to guessuntil I get the word. But if I was to typein the secret word, so if I was to type indraft here, now when I hit Enter, draft isequal to the secret word. So we're going tobreak out of that while loop. And we're goingto get this you win message. So that's essentiallyall our game did. It allowed us to keep guessingthe word until we got it? Right. So this isa pretty cool game. And you know, you guyscan see down here, it's actually pretty easyfor us to implement it. There's only you know,maybe like seven or eight lines of code. ButI think there's a little problem with thisgame. And the problem is that the user getsunlimited guesses, right? So the user canjust keep guessing infinitely. I mean, technically,technically, they could type in, you know,every possible combination of letters untilthey got the secret word, right. And that'snot a very good game, I think we'll make thisgame better would be imposing a guess limit.So we could say like, the user can only guessthree times or they can only guess four times.And if they don't get it in four guesses,then they lose the game. I think that wouldbe a little bit better game. So why don'twe try to implement that. Let's see if wecan come up with some code that will allowus to program that game. Well, I think I knowwhat we need to do. So the first thing wewant to do is we need some way to keep trackof how many times the user guesses right.If we're going to impose a guess limit onthis Game, we need to be able to keep trackof how many times they've guessed. So thatwas a good place to start, why don't we juststart with that I'm going to create an integer.And I'm just going to call it guest count.And we'll set it equal to zero initially,right? Because Initially, the user hasn'tguessed at all. And what we want to do iswe want to increment this variable every timethe user guesses. So let's go down here. Andyou'll notice this is the code down here,that allows the user to guess right, it'sthis code, which is essentially promptingthe user to guess and then storing their guests.So in addition to prompting them and storingthe guests, we can also increment the guestcount. So I can come down here and I can say,guest count plus, plus, right, just like that.So I'm incrementing, the guest count everysingle time they guess, awesome. But we'restill gonna need some more information. Soanother piece of information we're going toneed is the guest limit. So we need to essentiallytell our program how many times the user canguess. So I'm just going to make another andI'll just call this guest limit. And overhere, we can define how many times we wantthe user to be able to guess, well, why don'twe say three guesses? I think three guessesis enough, three strikes in your out. Andso now we're basically limiting the user tothree guesses. I also want to create one morevariable, and this is going to be a Boolean.And this is going to be called out of guesses.And I'm going to set this equal to false.And this Boolean is basically going to tellus whether or not the user is out of guesses.So if the user still has guesses left, thisis going to be equal to false. But if theuser is out of guesses, then this is goingto be equal to true. So we're going to setit to false initially. And then down here,we need to use these two new variables insideof this while loop. So the first thing I thinkwe should do is we should only allow the userto guess when they still have guesses left,right? In other words, I only want the userto be able to guess the word if they haven'talready guessed three times, right? If theyhaven't guessed the guessed limit. So whatwe can do is we can actually create an ifstatement. So I can say if and down here,I'm going to make open and close curly brackets.And inside of these parentheses, I need toput a condition. So let's think about this.What do we want to check? Well, I want tocheck to see if the user is out of guesses,right? So I can check to see if the guestcount is less than the guest limit. And ifthis is true, in other words, if the guestcount is less than the guest limit, then theuser still has a guest left, so they can goahead and guests. So I'm going to take allthis code for guessing. And I'm going to putit inside of these curly brackets. Right.So once again, we're checking this condition,if the guest count is less than the guestlimit, then we're gonna go ahead and printout all of this stuff. So we're going to allowthem to guess the word, and then we'll incrementthe guest count. But if this isn't the case,in other words, if guest count isn't lessthan the guest limit, that means that they'vealready reached their guests limit, right?That means they don't have any guesses left.So I can say else down here. And if they runout of guesses, what I want to do is I wantto modify this out of the guesses variable.So when they run out of guesses, in otherwords, when this condition is false, I wantto say out of guesses is equal to true. SoI'm going to say out of guesses is equal totrue. So basically, what we're doing downhere is we're saying, hey, they're out ofguesses. And this is actually what we calllike a flag. So you'll hear people sometimescall these like Boolean flags. And this isbasically just a value that's giving us apiece of information, right? This is tellingus that the users out of guesses. So there'sone more thing we have to do in this whileloop, you'll notice that this while loop isgoing to keep executing as long as the guestis not equal to the secret word. But now sincewe're adding in the gas limit, there's actuallyanother situation where we're going to wantto stop looping. And that situation is whenthe user is out of guesses. So I want to modifythis, I want to say that we want to keep guessingWow, they haven't guessed the secret word.And they're not out of guesses, right? Becauseif they haven't guessed the secret word, thenwe want to keep asking them. But if they ranout of guesses, then we want to break outof the loop, right? So I'm going to keep loopingwhile the guest is not equal to the secretword, and the user is not out of guesses.So now we have a while loop set up, whichis going to allow us to specify a guest limit.So there's one more thing we have to do, whichis down here. Now down here. We're basicallyjust saying you win, right? So whenever webreak out of the loop, we're telling themthat they won. Here's the problem though.So there's two situations now where they canbreak out of the loop when the guest is equalto the secret word in other words when theyguess correctly, but there's also anothersituation which is when they're run out ofguesses, right? And so down here, we're notgoing to be super sure which situation occurred.So what we can do is we can use another ifstatement. And we can check. So I can basicallysay if, and I can check to see if they'reout of guesses. So I can say if out of guesses.If this is true, then I want to print outa lose message. So I'm basically just gonnasay you lose. But otherwise, if it's not true,that means that they guessed the word correctly.So we can go ahead and put this win messagedown here. Alright, so that is essentiallyeverything we need to do to specify the guestlimit, I know this was a lot of code, whydon't we run our program, we'll play the game,make sure we got everything right, and thenwe can come back, and we can kind of go overwhat we did again. So I'm gonna run the program.It says enter guests. So I'm going to go aheadand lose the game. So remember, we have threeguesses, so I can just type in some randomguests. Another one. Now we're on our thirdand final guests. If I don't get the word,this time, we're going to lose, so I'm notgoing to get it. And I'm gonna click Enter,and it says, you lose. So it was able to figureout that we didn't guess the secret word andthree tries, and it told us that we lost thegame. Cool. So now let's see if we can winthe game. So I'm going to go ahead and runthis program, and it's gonna say enter guests.So let's enter two wrong guesses. Now we'reon our last try. Let's say I have a strokeof genius. And I type in the right word. Andit says, You win. So the program is now smartenough to play this game with a guest limit.Let's go over one more time, what we did,we created a bunch of variables up here, thesecret word is pretty obvious. The guest isjust storing what they guessed, the guestcount is keeping track of how many times theuser's guest right? So every time we run thecode to allow them to guess the word, we'regoing to increment it, the guest limit isjust telling us how many times they can guessin this out of guesses variable is basicallygoing to tell us whether or not the user hasrun out of guesses. And then down here wehave our loop. And this loop is basicallyjust going to keep going and keep asking theuser to guess the word. And it's going tokeep doing that as long as the guest is notequal to the secret word. And as long as theuser is not out of guesses. So if either ofthose conditions is false, we're gonna breakout of the loop, the first thing we do inthe loop is we basically use this if statement,and we say if guest count is less than guestlimit. And so if the guest count is less thanthe guest limit, in other words, if they haven'tguessed three times in our case, then we'regoing to prompt them for another guest. Butif they have guest three times, then we'regoing to set this out of guesses variableequal to true, and that's going to triggersome breaking out of the loop. So if we dobreak out of the loop, there's two situations,right? The first situation is that we wonthe game. And we guessed the secret word correctly.But the other is that we ran out of guesses.So down here, I'm basically checking thatI'm checking if we're out of guesses. If weare, that means we lost otherwise, that meanswe won. And so that's the basics of buildingthis program. And I do just want to say, thiswhile loop up here, we use a simple whileloop to do this. But you could also run thisprogram using a do while loop. And so if youwant to challenge if you really understandwhat's going on here, and you you know, you'repretty solid on what's going on, a good challengewould be to try and build this program witha do while loop instead of a while loop. Imean, it's gonna be pretty similar, a lotof the code can stay the same. But there aregoing to be some key differences that you'regoing to have to try to account for. So ifyou're looking for a challenge, try to buildthis with a do while loop. But otherwise,that's sort of how you build a guessing game.And you know, In this tutorial, we were ableto integrate a lot of the stuff that we'velearned up to this point in the course likevariables, we use all different types of variables,we use the loops, we also use if statements.So hopefully this gives you an idea of howyou could build something like this usingall that stuff. In this tutorial, I'm goingto show you guys how to use a for loop inC sharp. a for loop is a special type of loop,which allows us to keep track of what's calledan iterating variable. And basically, thisis just a variable that's going to changeevery time we go through our loop. So basically,it's it's kind of a situation where we havea variable and generally that variable willlike keep track of how many times we've gonethrough the loop, or it can keep track ofother things. But it's sort of a special scenarioin our programs where we want to use a loop.But we want to have a variable that's goingto be changing or doing something every timewe go through that loop. And this is actuallyreally easy to understand. I'm just goingto show you guys real quick this example thatI have down here, you'll notice that I havea simple while loop. So I said this integerI over here I said equal to one. And I'm loopingwhile i is less than or equal to five, right?This is a very simple while loop and everytime we go through the loop, I'm basicallysaying console dot write line I'm printingout I and then I basically saying i plus plusso a very simple loop. And but you'll noticehere when I run my program, I'm going to goahead and run it right now that I basicallyprinting out this variable i every time Igo through the loop, and you'll notice thatthe first time we go through the loop is equalto one, the second time we go through theloop is equal to two, the third time it goesthrough the loop is equal to three, this variablei is constantly changing every time we gothrough the loop. And I is actually tellingus what iteration of the loop we're currentlyon. This is pretty cool, right? This variablei is essentially keeping track of the timeswe've gone through the loop. And we can usethis variable i to you know, print that out,and to know where we're at, in the executionof the wild. This is actually a very commonsituation. So a lot of times when we're writingloops in C sharp, we're going to want to havea variable just like I a variable that's goingto change every time we go through the loop,right? In this case, I is changing every timeit's getting incremented by one. So I is essentiallytelling us how many times we've gone throughthe loop, but you can essentially use thisvariable to do anything. So instead of justincrementing it by one, I can get incrementedby two or I can increment incremented by anothervalue. And basically the idea here is thatwe have a variable that we're using constantlyas we go through this loop. And it's sucha common situation to have a variable likethis, that there's an entirely separate loopcalled a for loop, which is designed justfor this situation. So down here, I'm goingto go ahead and create a for loop. And I'llshow you guys how this for loop is actuallygoing to be able to do exactly what this whileloop is doing but a lot cleaner and a lotsimpler. To create a for loop, I'm just gonnasay for I'm gonna make an open and close parenthesesand open and close curly bracket. So so far,this is exactly like this Wilding, right,it's basically structured the same exact way.But you'll notice in the while loop insideof the parentheses, I only put one thing rightI put the loop condition, you'll hear peoplecall this the loop guard, right, it's basicallylike the condition for when we should loopinside of this for loops, parentheses, we'regoing to put three different things. So insteadof just having one thing, we're going to putthree things, the first thing we're goingto put in here is a variable initialization.You'll notice up here in my while loopingstructure, I have this integer I and overhere, I'm saying and i is equal to one. Butthis is actually outside of the while loop.So I had to do that separately from the actualwhile loop in a four loop, I can actuallydo this same thing inside of this parentheses.So I'm going to copy this, and I'm going topaste it over here. And you'll notice I'mgoing to leave this semi colon in. So thefirst thing I'm going to do inside this forloop parentheses, is I'm going to initializethis variable i. Now the next thing I wantto do, and you'll notice I'm separating thesetwo things with a semicolon. The next thingI want to do is write out my loop condition.So in the while loop, our loop condition isright here, you know what I mean? It's justi is less than or equal to five, whateverit's basically like telling us how long weshould loop for, I can just take this, andI can put this as the second item inside ofthese parentheses. So now I'm able to takethe variable initialisation and the loop condition.And finally, I'm going to put another semicolonhere. And I'm going to include one more thingover here. And this is going to be a lineof code that's going to get executed everytime we go through the for loop. Now you'llnotice up here in this while loop, every timewe go through this loop, we're doing somethingspecial to this variable, every time we gothrough the while loop, we're incrementingi and this is exactly what I want to do overhere in my parentheses. So the last spot insideof my parentheses over here, I'm just goingto put in i plus plus. And like I said, thisis just going to be a line of code that'sgoing to get executed after every single iterationof our loop. So you'll basically see thatI'm doing the same thing over here, as I amover here, right over here, I'm defining thisvariable, I'm initializing this variable witha value. I'm doing that down here in the parentheses.Over here, I'm specifying a looping condition.I'm doing that down here in the parentheses.And then finally down here after every iterationof the loop, I'm incrementing I. And I'm ableto do that over here in this third section.So basically, the for loop is just takingthis situation where we want to have a variablethat's going to, you know, be used insidethe loop. And it's compacting it into thisone single structure. And so now I can basicallycopy this line of code over here, paste itinto the for loop. And now these loops areidentical. So these loops are actually goingto be doing the same exact thing. And I'mgoing to prove that to you guys. So I'm goingto go ahead and get rid of this while loop.And we only have the for loop now and let'srun our program and see what output we get.So I'm going to run the program and you'llsee we're getting the same exact output thatwe got before we're getting 12345 printedout. So this for loop is doing exactly whatthat wildly was doing. It's just, it's a lotmore compact. It's a lot easier to manageand it's a lot better for us. So We walk youguys real quick through how this gets executed.Essentially, what happens is, the first thingwe do is we create this variable and we giveit an initial value. The second thing we dois we check this condition. If the conditionis true, then we're going to execute all ofthe code inside of here. Once we're done executingall that code, then we're going to go up hereand increment AI, then we're going to checkthe condition. Again, if it's true, we'llcome back down here, and we'll execute thiscode, then again, we're coming back up here,and we're going to do that and then we checkthe condition again. So it's continuouslylooping through just like that. And this isthe same as that while loop. So you coulddo what we're doing here with a while loop,it's just that it's a lot more convenient,and a lot easier to do it with a for loop.So that's kind of the basics of a for loop.And before I end this tutorial, I want toshow you guys one cool thing we can do withthese. Up here, I have this array that I created,and I just kind of commented it out. But I'mgoing to copy it and bring it down here. Andyou'll notice this is just an array of luckynumbers. So it's just an integer array, andI have these numbers in here, there's likefour different numbers, I'm gonna show youguys how we can use a for loop in order toloop through and print out all of the elementsinside of this array. So I just want to remindyou, the way that we can access an individualelement in an array is by saying the arraysname and then referring to the index of thatvalue. So if I said lucky numbers zero, thisis referring to this for if I said lucky numberstwo, this is referring to this 15. Right,basically, that's how we can access an elementinside of an array. For loops are really useful.Remember, we have this indexing variable.So I can use a for loop to actually loop throughand print out all the elements inside of anarray. So down here, so actually want to modifya couple of values, I'm going to say int i,instead of setting it equal to one, I'm goingto set it equal to zero, because array indexesstart at zero, so this element is elementzero inside of the array, then I'm going tochange this condition. So instead of sayingi less than or equal to five, I want to sayi less than or equal to lucky numbers dotlength. So this is going to allow me to accessthe length of the array. So when I say luckynumbers dot length, this is going to tellme how many elements are inside of the array.Then down here, I'm going to say console dotwrite line, and I want to print out luckynumbers I. And the way this is going to workis the first time we go through this loop,we're going to be printing out lucky numberszero, right, because I is initially goingto be zero. So the first time we go throughhere, we're basically printing out lucky numberzero, the second time we go through, I getsincremented. So we're going to be printingout lucky numbers one, the third time, we'regoing to be printing out lucky numbers two,etc. So we can use this for loop in orderto loop through this array. Let me show youguys when I run this program, and actually,you know, I forgot to modify one more thing.So instead of saying less than or equal tohere, I'm just gonna say less than. And basically,since we're starting at zero, I want to sayi is less than lucky numbers dot link, that'sbecause the length of the array is going tobe 123456. But the last element in the arrayis an index position five. So if I say i isless than or equal to lucky numbers dot length,then we're going to be trying to access luckynumbers six at one point. But the last elementis it lucky numbers five, so we have to sayless than so I'm going to change this backto an eye. And let's go ahead and run this.And you'll see that we'll be printing outall the elements inside of that array. Sowe're printing out for 815 1623 42. So that'sone very common use of these four loops isyou can use them to loop through all the elementsinside of an array. In this tutorial, I'mgonna show you guys how to build an exponentfunction in C sharp, an exponent functionis basically a function where we can passin two numbers, a base number and a powernumber. And it'll take the base number tothe power number. So essentially, it's gonnalike if I passed in a two and a three, itwould give me two raised to the third power,right, or if I passed in a four and seven,it would give me four raise to the seventhpower. That's essentially what where you wantto write in this tutorial. So I'm gonna comedown here below my main method, and I'm actuallygoing to create this function. So I'm justgoing to say static. And we're actually goingto return a integer. So why don't we justhave this except integers, we'll just keepit simple. And I'm just going to call thisget POW. So this will basically like get thepower. And I'm going to make some open andclose curly brackets. And in here we're goingto accept two parameters. So the first isgoing to be an integer base num, and the secondis going to be an integer power num. So we'llbasically take the base num and raise it tothe pound right So a base number two and poundon three, then we'll do two cubed, right?It kind of makes sense. So this is going tobe a cool little method. And it kind of posesan interesting challenge, because we don'tknow what base num and power num is. Right?If we knew what power number was, for example,if we knew power number was two, then I couldjust say, base num times base not right, Icould just square base num, and we'd be goodto go. But I don't know what power num is.So I don't know how many times I need to multiplybase num by itself, in order to get the answers.So this kind of poses an interesting challenge.And I'm gonna show you guys how we can usea for loop to solve this challenge. So thefirst thing I want to do is just create aninteger. And I'm just going to call this result.And I'm just going to set result equal toone. And then eventually, what we want todo is return result. So we want to modifyresult enough where it represents bass num,taken to power numb, okay. And what we needto do is we need to keep multiplying resulttimes bass num, power num times. So let meshow you guys, we can create a for loop. AndI'm just going to create a simple for loop.And remember, when we're creating for loops,the first thing we want to do is create avariable. So I'm just going to say int i isequal to zero, and I'm going to start thisoff at zero, then what I want to do is createa looping guard. So what condition in otherwords, we're saying we want to keep loopingas long as this condition is true. So I wantto keep looping as long as i is less thana pound. And when I say this, this is basicallytelling C sharp that I want to keep loopingpower num times. So if power num is equalto three, we're going to execute this loopthree times if count is equal to five, orexecuted five times etc. And the last thingwe want to put inside of this for loop isgoing to be something want to do after eachiteration of the loop. So I'm just going toincrement i. And this is a very, very, verysimple for loop. So we're looping throughhere, power num times. So like I said, Ifcount is two, we'll go here through here twotimes. And every time I go through this loop,I basically just want to multiply result,times base nom, so I can say result is equalto result times base num, just like that.So the first time we go through this loopresult is going to be equal to one, right,so the first time we go through result isgoing to be equal to one. So now result willbe equal to one times based on right, thefirst time through results gonna essentiallybecome equal to based on the second time wego through results equal to base num, right,so we're essentially multiplying base numby base num, in other words, based on m squared,and storing it inside of this result variable.And we're going to keep doing that througheach iteration. So if we go through this loopthree times, then result is going to havethe value of base num cube, if we go throughthis loop, five times result will have thevalue of base num taken to the power of five,right? And then down here, we can just returnresult. So by using this for loop, we're actuallyable to figure out what the answer is. Soup here inside my main method, let's go aheadand run this. And I'm actually going to printout the answer. So I'll just say, consoledot write line, and we're going to write theresult of get POW. So why don't we try todo like three squared, right, so pass in threeand two. And I'm going to go ahead and runthis program. So we should get the resultof three squared, which is going to be nine.And you can see over here, we get nine. NowI just want to point out this, this get powermethod is only going to work for positivenumber powers. So we're not going to be ableto do like three and negative two. That'snot going to work down here. But we can dopositive number exponent so I could say likethree two, why don't we try like four andthree so this is going to be four cubed. Sowe should get 64 and yeah, we get 64 Alright,so it looks like this methods working so onceagain I'll just walk you through what we did.This get power method accepted two parametersbass num, and power num. So the goal was totake bass num to power them. We created thisfor loop over here and essentially all I didwas I said I equal to zero. And we're goingto keep looping as long as i is less thanpower num and what that means is we're goingto go through this loop power num times. Soif lb M was five that means we went throughthis for loop five times. And every time wewent through this for loop, we multipliedresult which was initially equal to one, wesaid result is going to be equal to resulttimes base num. So the first time throughthe loop, result was equal to one so we endedup getting result is equal to one times basedon so we got based on second time throughthe loop result was equal to base num. Sowe said result is equal to base num timesbase. Not Essentially, the third time throughthe loop result was equal to base num squared.So essentially, we were saying result is equalto base num squared times base node basedon cube. And that's essentially what we did.And that was actually enough for us to getbase num taken to pound them. So it's a prettysimple method, although it is a little bitcomplex, because we use this for loop. Sowhat you should do is play around with thismethod, and you know, write it on your ownand see if you can really wrap your head aroundwhat's going on here. In this tutorial, I'mgoing to show you guys how to use two dimensionalarrays in C sharp, a two dimensional arrayis basically a situation where we have anarray, and every element inside of that arrayis itself an array. So essentially, we'rebuilding like a little matrix structure insideof our program. And I'm gonna show you guyshow we can do that, it's actually pretty simple.So if we want to create a two dimensionalarray, we can do it just like we would a normalarray. So I'm going to create an array ofintegers. So we'll just say ends. And nowwhat I want to do is I want to make an openand close square bracket and inside of thisopen close square bracket, I'm just goingto put a comma here. And basically, this istelling C sharp that we want to have a twodimensional array. And I'm going to give thisa name. So I'm just going to call this numbergrid. And I'm going to go ahead and set thisequal to something. So now what we can dois we can actually fill this array with abunch of different elements. So I'm goingto make an open and closed curly bracket,and then I'm going to make a new line anddown here, we're actually going to be ableto populate this array with elements. So ifI was making a normal array, I would usuallyjust put in like a bunch of numbers, so I'dsay like 1234, etc. But when we're makinga two dimensional array, all of the elementsinside of this array need to be arrays, sothemselves, they have to be array, so thefirst element has to be an array, and thesecond element would have to be an array,and the third element would have to be anarray excetera. All of these elements haveto be arrays, and then I could give thesevalues. So I could say like 112. And thendown here, we could say like three, four,and we could say five, six. So basically,now we have a little matrix of numbers, right?Not only does the number grid have three elements,but each of the elements inside of the numbergrid has two elements inside of it. And thisis a two dimensional array. So let's lookat how we can actually access some of theseelements, what I can do is I can come downhere, and I'm just gonna say, console dotwrite line. And if I wanted to, like for example,let's say I wanted to print out this elementover here, I can just refer to the name ofthe array. So I can say number grid, and thenI'm going to make an open and close squarebracket. And in here, I'm going to put twonumbers. So the first number I'm going toput is going to be the element inside of thearray. So it's going to be like this is thefirst element, this is the second, this isthe third, or this is element at index positionzero, this is element at index position oneindex position two, etc. So I'm gonna puta zero because we're trying to access thisone over here. And then I'm going to put anotherzero, so I'm just going to put 00, and that'sreferring to row zero, column zero. Now whenI run this program, it's going to be ableto print that out. So you'll see we're printingout one, we're printing out that element overthere. Let's say that I want to access thisfour over here, well, this is going to berow 01. So I'm gonna put a one right here.And then it's going to be 01. So it's goingto be one, one. And now when we print thisout, we should get a four, which we do. Sothat's essentially how you access those elementsinside the array. And this works exactly likeit does with a normal array. So if I wanted,like I can modify one of these values, I cando everything that I would do in a normalarray. And that's kind of the basics. Thisis a structure that you might not use allthe time. But when you need it, it's extremelyuseful. And in addition to two dimensions,you could also have like three, or four orfive dimensions, all you have to do is justput more like commas over here. There's alsoa situation where you might not know how manyelements you want to go in there initially.And you could actually just like declare oneof these, so I can say like and, and I'llmake a two dimensional array, and we'll justcall this like my array. And if I don't knowwhat elements I want to put in here, initially,I can actually just say equals new int. Andthen over here, I need to give this some information.So I'd have to say like two, three. And thisis basically telling C sharp how many rowsand how many columns we want to have. So thiswould mean there's two elements and then eachof those elements has three elements insideof it. So that's another way that you coulddo that. And then you could just manuallylike insert the elements. In this tutorial,I'm gonna show you guys how to use commentsin C sharp. Now comment is basically justa special line or block of text in our programthat's going to get ignored when we run program.So comments are really useful for leavinglittle notes or comments inside of your program.And a comment is essentially just a line ofcode that's meant for humans, and not meantfor the computer. And these can come in handy.So I'm going to show you guys basically howthese work and what we can do with them. IfI wanted to create a comment, I can just comedown here and type two forward slashes justlike that. And now you'll see that the textin my text editor has changed color, it'snow this green color. And that's basicallysignifying that we have a comment here. Solike I said, a comment is a little line ora little block of code, that's actually goingto get ignored by C sharp. So when I run myprogram, anything that I have inside of thiscomment is just gonna get ignored. The commentis for the programmer, so it's for me, orit's for another developer who comes in andis reading my file. So I could leave likea little note here, I could say like, a todo, like, you know, maybe this block of codeneeds to be done. Or I can even come in hereand like describe a line of code. So I coulddescribe this line of code over here, I couldsay like, this prints something out, etc.You could also take these comments and putthem after a line of code. So I can come overhere and say, two forward slashes, and youcould type out, you know, a comment, whatever.And this is what we call a single line comment.So a single line comment is a comment thatcan only be on one line. So if I was to makea new line you see down here, this is no longera comment. And you'll see it's actually throwingan error because the program is trying torender it as actual code. But in additionto single line comments like this, a lot oftimes, you're going to want to have commentsthat are span multiple lines, one thing youcan do is just make multiple lines like that.And then you'll see a lot of developers dostuff like that, you can also use a startingand an ending tag. So you can type in a forwardslash, and a star. And now everything thatcomes after this forward slash and a starin our file is going to be considered a comment.That is until we end it off with another starand a forward slash. So I can say star forwardslash, and now you'll see only the stuff that'sin between these two little tags, is goingto be considered a comment. And these cango on multiple lines. So those are basicallythe two types of comments that we can use.And really a comment is extremely open ended.I mean, there's no wrong way to use a comment.It's really however you want to use it. AndI do want to show you guys one other way thesecan be useful. So let's say that I'm writingcode, and you know, I want to try and runmy code without a certain line in it. So maybeI'm like, you know, have a program. And Ithink one line might be causing it to break,or I just wanted to see what it would looklike without a single line of code. Well,one option would be to remove that line ofcode. So for example, I can take this lineof code, maybe this is a line of code thatI think is causing my program problems, Icould delete it, and then I can go ahead andrun the program, right, and then nothing getsprinted out. But here's the problem, whenI do that, I have to actually like physicallyremove the line of code. Instead, what I cando is comment it out. So I could just puta comment in front of this. And now this wholething is basically going to get ignored byC sharp, so I can run the program. And we'restill going to be running it without thatline of code. But I don't have to physicallydelete it from the file. And that just allowsme to keep track of it a little bit better.And you know, I can still have it there, it'sstill taking up space in the file, it's justgoing to get ignored. So that can be a reallyuseful way. So really, I'd say comments, youknow, are basically used for two things. Thefirst is like writing out little messagesor notes, either for yourself or for otherprogrammers, or for commenting out lines ofcode. And you'll see people do both of those.And they're both really awesome. So like Isaid, comments are pretty much open ended,you can do whatever you want with them. ButI'd say those are the two most common usecases. In this tutorial, I'm going to showyou guys how to use Exception Handling inC sharp. A lot of times when your C sharpprograms are running, there's gonna be certainthings that can go wrong. And generally, whenthose situations occur, C sharp is gonna throwwhat's called an exception. An exception basicallyjust tells you that something happened inyour code that C sharp couldn't handle. Andwhenever an exception gets thrown, generallythe program crashes. So there's a lot of situationswhere something might happen in the executionof the program, and exceptions gonna get thrownand then the program is going to terminate.And sometimes you're going to want that tohappen. Sometimes when an exception gets thrown,you're going to want the program to terminatebecause you're going to want to know whathappened. But a lot of times, especially ifyou're writing a program that's being designedto run for, you know, months and months ata time, you're not going to want an exceptionto crash the program. In other words, you'regoing to want the program to be able to keepgoing when something wrong happens and anexception gets thrown. So I'm going to showyou guys the basics of working with exceptions.We're also going to talk about handling exceptionsand the different scenarios. where an exceptionis gonna get thrown down here I have a basicprogram written out. And this is a very simpleprogram, essentially all it does is it getstwo numbers from the user. And it takes thosenumbers, and it divides them. So you see overhere, I have console dot write, I'm askingthem to enter a number. And then I'm takingwhatever they entered, and I'm convertingit into an integer. And I'm storing it insideof this integer variable. And I'm doing thatfor both of these numbers, then down here,I'm just writing out the value of dividingboth numbers onto the screen. So there's twomajor things that we're doing here. The firstis we're converting this string into an integerusing this convert instruction. And then downhere, we're dividing the two numbers, andI'm gonna show you guys how we could actuallyenter in information to this program thatwill cause exceptions. So let's go ahead andrun this. And I'm just gonna click Start.So over here, I'm going to answer a number.So why don't we enter in a five. And now I'mgoing to show you guys one way that an exceptioncould get thrown. So remember, we're dividingthese two numbers, and you can't actuallydivide a number by zero. So just by basicmath rules, if we have a whole number likethis, it's impossible for me to divide itby zero. So essentially, what I'm doing hereis I'm asking the computer to do somethingimpossible, right? I'm asking the computerto do something that it's not going to beable to do, and it's not going to be ableto handle when I hit Enter, and I asked thecomputer to do this, it's gonna throw an exception.In other words, the computer is going to belike, Hey, I can't do this, like I can't dividethese two numbers. So the program is goingto terminate. So you'll see when I hit Enter,that this little screen goes away, and thisexception pops up. So it says exception, unhandled.System dot divide by zero exception attemptedto divide by zero. It's basically tellingus what went wrong, right? saying, hey, youtried to divide by zero, that's illegal, youcan't do that. And we can't handle that. Sobasically, it's throwing this exception. Soyou can just come up here and click stop debugging.And that'll make that go away. I'm gonna showyou guys one other way we can break this program.So if I put a number in here, like a four,that's all well and good, right? But remember,we're converting whatever is up there intoa number. So if I was to type in like a G,this isn't a number, right? G is not a number,it has no numerical value. So the programisn't going to be able to convert g into aninteger, even though I asked it to. So whenI hit Enter, another exception is going toget thrown This time, we're getting a formatexception, it says input string was not incorrectformat. In other words, we asked you to entera number and you entered in a character, theprogram can handle that. So it breaks. That'sanother example of an exception. So the questionbecomes, what do we do about this? Right?Our program keeps throwing these exceptions.So how can we handle that like, if the userenters in a letter, instead of a number, Idon't want the program to terminate, I wantto be able to do something else, like I wantto be able to yell at them and be like, hey,you entered in the wrong thing, I don't wantthe program to terminate. Or if the user triesto divide by zero, you don't want the programto terminate, you want to tell them that theyentered in an invalid number. So if we wantto do that, we can actually do something calledException Handling exception handling is basicallythe process of catching these exceptions.So we're basically going to tell C sharp like,hey, there's some code over here that mightthrow an exception. If it does, we want youto catch it. And instead of crashing, we wantto be able to handle it. I'm going to showyou guys how we can do that. So we want touse something called try catch blocks. SoI'm just going to type out try and open andclose parentheses, curly bracket. And thendown here, I'm going to type out catch, andagain, an open and closed curly bracket. Sotry catch blocks work like this, any codethat we think is going to break the program,for example, the code down here, we can putinside of these try blocks. And if that codedoes indeed break the program, then insteadof the program terminating, the program isgoing to go down here into this catch block.And it's going to execute all the code downthere. So what I want to do is take all ofmy risky code, in other words, all of thisstuff, and I can place it inside of thesetry blocks. So I'm just going to paste itinside of here. So now all of this code thatpotentially would break the program is insideof this try block. So what I want to showyou guys, now that I have this catch blockover here, I can just do like console dotwrite line, and over here, I'm just gonnaprint out error. So essentially, what's goingto happen now is if any of this code causesan exception, we're going to come down hereand print out there. So let me show you guys,I'm going to go ahead and run this program,and it says enter a number. So let's do the01. Again. So now I'm going to hit zero, thisshould break the program. But now insteadof breaking the program and causing an exception,we just print out error. So it's, it's kindof like a backup system. And what we can alsodo is we can get more information about theerror that occurred so I can say catch, Ican make an open and close parentheses andthen I can say, exception, and I can justcall this E. So basically saying that thiscatch block is going to take a an exceptionparameter and we're going to call it E. IfI came over here now I can basically printout E. And I can say e dot message. And thisis going to tell me what went wrong. So nowwhen I run my program, and when we can dothat zero division, I'll say five dividedby zero, and it's going to tell me what wentwrong, it's gonna tell me you attempted todivide by zero, if I did the other error,so for example, if I entered in a letter likeGE, now it's going to tell me input stringwas not in correct format. So it's able tocatch the error that happened. And by sayingexception II appear in these parentheses,we can actually get the error message justlike that. So this is a really great way tokind of stop our programs from terminating.But here's the thing, there's all differenttypes of exceptions that can get thrown insideof our programs, right. And all I have downhere is one catch block. So no matter whatexception gets thrown, we're always executingthis same code down here. But let's say therewas a situation where when the zero divisionerror occurred, you wanted to do one thing.And when the input error occurred, you wantedto do a different thing, we can't really dothat, because we only have one catch block.Well, what we can do is we can actually definespecific exceptions that we want to catch.So down here, instead of saying exception,I can actually specify a specific type ofexception that I want this catch block tocatch. So before we were getting a divideby zero exception, so I can put this in here.And now this is only going to catch a divideby zero exception. So if I was to run my program,and we did the divide by zero, I'll say fivezero, you'll see it's able to catch it. Butif I was to do that invalid format, but Icame over here, and I said, like six, andthen I said, Gee, it's not going to be ableto catch that. So down here, we're gettingthis format exception, right. And basically,it's not being caught because we didn't specifyit down here, this catch block is only goingto catch divide by zero exceptions. But whatwe can actually do is we could make anotherone. So I could say, catch, and in here, I'mjust gonna type in format exception. And nowthis is going to be able to catch any formatexceptions that occur. So now I can say consoledot write line. And again, we can just printout like e dot message. And so the idea isthat instead of just printing out a message,you would do something different dependingon the error that gets thrown. In our case,though, we're just gonna say e dot message.So now when I get that format exception, ifI say like five, and then G, it's gonna sayinput string was not in correct format. Soit's able to catch both of those. And that'sessentially what you want to do. So what wewere doing before is we just had, like, catch,and we were just kind of catching any exceptionunder the sun. But now we're catching individualexceptions. And this is actually a betterway to do it. Because we're able to accountfor each of these situations, right? Whenthe user divides by zero, we could print outlike, Hey, you divided by zero, like watchit. If they have a format exception, thenwe could do something else, like maybe wecould prompt them to enter that input again,or, you know, we could do something else.And so being able to have these multiple catchblocks, is extremely useful. There's alsoone more thing I want to show you guys, whichis called finally So down here, I can justtype up. Finally, and I'm gonna make an openand closed curly bracket. And any code thatwe put inside of this, finally, block is alwaysgoing to get executed no matter what, rightno matter what it's going to get executed.So for example, up here, this code, like ifthe user enters in an invalid number, likeif they enter in a letter here, instead ofa number, this code won't get executed, right?Because we threw the exception, and we brokeand we came down here. But sometimes in yourprograms, even if something throws an exception,you're always going to want to execute something,and that code can go down here in the finallyblock, but you don't always need finally blockedoff kind of optional. So really, this is justhow we can handle different errors in ourprogram. And there's a bunch of differentexceptions. If you just go online and youknow, search for like C sharp exception list,you'll find a bunch of these different exceptions.And this really just makes your programs moredurable. Like before, this was a very fragileprogram. If I entered in a letter insteadof a number, like he would just crash andburn. But now we're actually able to handleall those different situations using thesetry catch blocks. So these are extremely useful.And anytime you have code that's a littledicey, especially if you're like getting inputfrom a user and stuff like that, these cancome in handy. In this tutorial, I'm goingto show you guys how to use classes and objectsin C sharp classes and objects is actuallya big subject. And there's a lot for me totalk about in this particular topic, but thisvideo is just going to be a very basic introductioninto what classes and objects are and howwe can start using them in our C sharp programs.Now in C sharp, we're going to be dealingWith all types of data, and a lot of timeswhen you're writing your programs, you'regoing to want to work with and represent differentthings in your programs. And by default, Csharp gives us a bunch of different data typesthat we can work with. So in C sharp, we canrepresent things like text. So we can usestrings to represent text, we can representcharacters, we can represent whole numberswith integers. And we can represent decimalnumbers with things like doubles and floats,right, we can also represent true and falsevalues with Boolean variables. But here'sthe problem is with just those limited datatypes, we're not going to be able to representor model everything that we'd want in ourprograms. In other words, there's a lot ofthings in the real world that can't just berepresented using a string or a number ora Boolean, right. I mean, think of somethinglike a phone, for example, like imagine Iwanted to represent a phone inside of my program,well, I can't represent a phone with likea string, you know, I can't represent a phonewith just a number, like a phone is a complexentity in the real world. And I can't sortof break it down into just one single, likestring or number, right, I can't representit using just one of those data types. Andthat's kind of one of the limitations thatyou're going to encounter is like, you can'trepresent everything just using one of thesedata types. So what I want to talk to youguys about today is something called classesand objects. And classes. And objects essentiallyallow you to create your own custom data types.By default, were given things like strings,numbers, and Booleans. But I could actuallycreate my own data type that would allow meto represent something that I wanted insideof my program. So generally, what we'll dowhen we want to create a data type in C sharpis we'll create something called a class.And a class is basically just a specificationfor a new data type. So I could create a classfor a phone or I could create a class forlike a water bottle, or I could create a classfor a keyboard or a computer. And then I couldrepresent all those different things insidemy programs. So classes are basically useto model real world entities inside of ourprogram. So I'm going to show you guys howwe can build a class. In order to do that.The first step when you want to build a classis you want to open up your solution explorerover here, and my case is just over here onthe right side of my screen, and I'm goingto go down to my project. So I'm over herein my draft project. And when I want to createa new class, I can just right click, and I'mgoing to go down to add, and I'm just goingto click New Item. And then over here, weshould get this little menu that pops up andit says, class, this is the first one rightup here. So I'm going to select that. Andthen I can actually come down here to thebottom and give this a name. So I'm goingto go ahead and name my class. And generallywhen we're creating a class in C sharp, youwant to name it with a capital letter. soin this situation, I think we should createa class for a book. So let's say that I waswriting a program, maybe this was a programfor like a library or a school bookstore.And I wanted to be able to represent a bookinside of my program. So I want to createa book data type. So just like I create astring, or I create an integer, or I createa Boolean, I want to be able to create anactual book inside of my program. So I'm gonnacreate a book class. And I'm just going tocall this book.cs. And I'll hit Enter. Andyou guys will see over here that another filehas been added to our solution explorer. Sonow we have this book.cs file. And you'llnotice that this is pretty much laid out exactlylike the other one. So exactly like this programclass that we were using over here. And it'sbasically just like an empty class. So rememberwhat I said a class is essentially just aspecification for or really, it's like a blueprintfor a new data type in our program. And oneof the cool things about C sharp is it actuallyallows us to, you know, specify a custom datatype. And essentially, what we want to dois we're going to be creating a complex datatype.So a string, for example, is a data type,right. And all it is is just plain text. Anumber is a data type. And all it is is just,you know, a number, right, we have integers,we have floats that are whole numbers anddecimal numbers. But when we create this bookdata type, it's actually going to be composedof all of those other data types. So insideof here, we're going to define a series ofattributes. And these attributes are basicallygoing to describe what a book is inside ofour program. And that's generally what youwant to do. When you create a class, we'regoing to take a class, and you're going togive it a series of attributes. And like Isaid, those attributes will kind of definewhat it is. So I have this book class. AndI want to think about what are the differentattributes that are going to allow me to representa book inside of my program. And what I wantto do is I want to actually create variablesfor each of those. So let's think about this.What are the different attributes of a bookWell, I can think of the first one is goingto be title. So over here, I'm gonna say stringtitle. And before I say string title, I'mgonna say Public. So I want to say publicstring title. And I'm actually going to makethis lowercase. So that's one attribute thatwe can store about a book. What's anotherone? Well, let's think we would also wantto store the book's author. So I can say publicstring author. And let's just try to thinkof one more. So I think one more good onemight be the number of pages. So I'm gonnasay public, int pages. And all of these differentvariables that we're declaring over here arecalled class attributes. And these are essentiallypieces of information that are describingwhat a book is in our program. So I'm essentiallymodeling the book data type, I'm creatinga blueprint for the book datatype, I'm sayingthat inside of our program, a book is goingto have a title, an author, and a number ofpages. So this is a specification, it's atemplate. Now, what I can do is I can go offto my other program, and I can actually createa book inside of my program. So just likeI create a string, or I create an integer,or I create a double or a Boolean, I can createa book, and I can store it inside of a variable.And we can actually create something calledan object, which is going to be a actual bookinside of our program. So I'm gonna show youguys how we can do that, I'm going to savethis file. And I'm going to head back overto program.cs. So this is like the file thathas our main method over here. And I wantto show you guys how we can create a booknow. So if I wanted to create an representan actual book inside of my program, sinceI've created that class, and I define whata book is, I basically defined the book datatype,I can actually do that. And I can create somethingcalled an object. And an object is an instanceof a class. So when we created the class,we created the template for what a book is,when we create an object, we're creating anactual physical book inside of our program,right? So over here, this class specifiedlike a title, author pages, right? This isa specification for what a book is, when Icreate a book object, I'm creating an actualbook with an actual title, actual number ofpages and an actual author. So I'm gonna showyou guys how we can do that. The first thingI want to do is I'm basically going to createthis, like I would a normal variable. So thefirst thing I'll do is specify the data type.And in our case, we're going to create a bookusing the book data type. So just like ifI was creating a string, I would say, likestring, you know, whatever is equal to whatever.Here, I'm just gonna say book. And we're gonnado the same thing. So I'm gonna say book,I'm going to give this a name. So why don'twe just call it book one. And now what I'mgoing to do is set it equal to new book, andan open and close parentheses. And this ishow we can create what's called a book object.This is essentially an instance of a book.So this is like a physical book inside ofour program. So the class is a specification,the class tells us what the book data typeis, an object is an actual instance of thatclass. All right, hopefully that makes sense.So now I've actually created this book calledbook one. And we can use book one over here,just like a variable, I mean, it's essentiallyjust a variable that's storing a book object.So remember, the book has all these attributes,right? So a book can have a title, a bookcan have an author and a book can have a numberof pages. So when we create our book, we wantto give it all of those attributes. So whatI can do is I can say like book one dot, andnow I can access the attributes. So I couldsay book one dot title, and I can actuallygive this a value. So let's say that we wantedto create an object that would represent oneof the Harry Potter books. So I could saybook, one dot title, is equal to Harry Potter.So now the title of my book is going to beHarry Potter. Let's come down here. And we'llsay book, one dot author, and the author ofthe Harry Potter books is JK Rowling. So I'mgonna say book, one dot author is equal toJK Rowling. And then finally, down here, we'regonna say book one dot pages. And let's justsay that this Harry Potter book has 400 pagesin it. So what I did was I created a bookobject was, which is an instance of the bookclass. And I was able to define all of thepieces of information about this book. SoI define what the book's title was, I definewhat the book's author was, and I definedhow many pages the book had. And so now whatI can actually do is I can work with thispiece of information. So I can say like consoledot write line, and over here, I could printout some attributes of the book. So I couldsay like book one dot title, and now whenI run my program, it's going to print outthe title of the book we just created. Soit should print out Harry Potter. I can dothe same thing for the other attributes. SoI could say like book one dot pages, and nowwe're going to print out however many pagesbook one has, so we're going to get 400. Soessentially, I'm creating here a book, right?I defined the book data type in that class.And now I'm creating an actual book insideof my class, which we're calling an object.And what's cool about these objects is I cancreate as many objects as I wanted. So I couldcome down here, and I could actually makeanother object. So I'm going to copy thisguy. And I'm actually going to paste it downhere. And instead of being book one, I'm goingto change it to book two. So this is goingto be Book Two, Book Two, Book Two, book two.So let's start giving this some differentinformation. Let's say this object is goingto represent one of the Lord of the Ringsbooks. So I could say, Lord of the Rings,and then the author is token and let's saythe Lord of the Rings has like, I don't know,700 pages in it. So now I have a book up herecalled book one, which is representing theHarry Potter book. And then I have anotherbook down here, Book Two, which is representingthe Lord of the Rings book. And I'm actuallyable to have an actual book in my program,right, so I'm able to represent and storeand work with and model a book inside my program.So down here, I could do the same with BookTwo, I could say like Book Two, dot author,and now this is going to print out the authorof book two. She'll see over here, we gettoken. Now I want to bring up one point. Soboth of these objects are books right overhere. In this book class, I defined the bookdatatype, I basically told C sharp like, Hey,we got a new data type. It's a book, it'sawesome. All books have a title and authorand a number of pages. And over here, I createdindividual books off of that blueprint offof that template. Right. So book, one is itsown book. It has its own title, its own authorand its own pages, Book Two, down here isanother book. And it has its own title, itsown author and its own pages. So if I wascreating an application for like a library,for example, let's say the library had 10,000books. Well, I could create 10,000 objects,all of which would have the title, the authorand the number of pages of each one of thosebooks. And then I could work with those books,I could pass them into methods, I could usethem in if statements, I can do all sortsof stuff with those books, just like I wouldwith other data types, like strings, numbers,or Booleans. So classes and objects are extremelypowerful. And really, this is just scratchingthe surface. This is like lesson one. Youknow, this is the bare basics of working withclasses and objects. As we go forward. Forthe next few videos, we're gonna learn allsorts of ways to make these a lot more powerful.In this tutorial, I want to talk to you guysabout using constructors in C sharp classes.A constructor is basically a special methodthat we can put inside of a C sharp class,which is going to get called whenever we createan object of that class. So anytime I createan object of a specific class, the constructormethod will get called. And we can do differentthings. So I'm going to show you guys howwe can leverage that constructor method inorder to make it a lot easier for us to createobjects off of the classes that we createin C sharp. So down here, if you're not followingalong with the course, I basically createda class over here called book. And I justcreated this book class. And I basically saidthat the book is going to have a title andauthor and a number of pages. That's kindof all this book is. And then over here inmy program.cs, and my main method, I createdtwo books. So I created a Harry Potter book,and I created a Lord of the Rings book. NowI want to show you guys how we can use a constructorand we're actually going to be able to usea constructor to make it a lot easier forus to create these objects. But before wedo that, I just want to give you a introductioninto what constructors are, and kind of showyou what's happening. So over here in my class,I'm actually going to create a method downhere, I'm just gonna say public book, I'mgonna make an open and close parentheses andopen and close curly bracket. Now you'll noticethat I said public and then I said the nameof the class. And this is what's called aconstructor. So anytime I make a method likethis, where I'm saying public, and then thename of the class, this means that this isgoing to be the constructor for this class.And like I told you guys before, the constructoris basically a special method inside of ourclass, that's going to get called when wecreate an object of this class. So let meprove that to you guys. I'm going to comedown here and I'm just going to type out consoledot write line. And I'll make an open andclose parentheses and down here, I'm justgoing to write creating book. Okay, very simple.Now over here in my program in my main method,I'm going to run this and what you're goingto see is every time I create a new book,this line and this line that is going to getexecuted, so I'm going to run the programand you'll see over here it says creatingbook and creating Book, essentially, what'shappening is when I come down here and I saynew book, what I'm doing here is I'm actuallycalling that constructor method. So this righthere, this line where I'm saying new book,this book is directly linked to this methodover here. And again, I'm going to prove thisto you. So over here, what I'm going to dois I'm going to say that this book method,this constructor should accept one parameter.So I'm gonna say, string name, that's allI'm gonna say. And then down here, I'm justgonna print out name. So this method is acceptingone parameter name, and then down here, we'regonna print it out. Over here, you'll noticeI'm already getting errors. And that's becauseI didn't include a parameter. So I can comeover here and say, like, Mike, and then downhere, we can pass another name like john.So now when I run my program, it's going toprint out Mike, and it's going to print outjohn, because I'm calling that book constructor.Awesome. So not only does this call that constructor,but from here, we can also pass parametersinto that constructor. And that is extremelypowerful. So I'm going to show you guys whatwe can do with that information. Now, let'stalk about the code that we have over here,you'll notice that I have a bunch of codehere. So when I created this Harry Potterbook, it took me four lines of code, right?When I created this book to this Lord of theRings book took me another four lines of code,total of eight, eight lines of code just tocreate two objects, right, just to createtwo books, I had to write out eight linesof code. Not only that, I had to manuallytype out book one dot title is equal to HarryPotter book, one dot author is equal to JKwrong, like, that's a huge drag. You know,having to do that every single time you wantto create a book is extremely annoying. Andimagine if we were instead of creating twobooks, we were trying to create 10 or 12,or 20 books, right, it would take forever,because we'd have to manually go through and,you know, assign a title and an author anda number of pages. So this is a totally validway to create our object and give it someattributes. But there's actually another way,and we can use that constructor to do it.So essentially, what I want to do is I wantto allow the caller to pass in a title andauthor and a number of pages into this bookconstructor. So when they create the book,I want them to be able to tell me what thetitle is going to be, what the author is goingto be and what the number of pages is goingto be. That way, they can just tell me rightaway, and I can handle it up front. And thenI don't have to say like book, one, titleis equal to whatever book one dot author isequal to whatever. So let's see if we canwire that up over here. Again, this book constructoris going to take in three parameters. Andwe already saw before that over here, we canpass parameters into here, right, so I canpass a parameter into here, and it's goingto get passed into that constructor. So I'mgoing to say that this constructor is goingto take three parameters, the first is goingto be a string, and I'm going to call thisa title. And this is going to stand for argumenttitle. And you guys will see why I'm namingthis differently in a second. And then I'mgoing to make another string, I'm going tocall it a author. And then I'm going to makean int, and I'm call it a pages. Now, essentially,what's happening is whenever we create a book,we need to pass in the title, the author,and the number of pages. And so what I cando now is from inside of this constructor,I can just come down here and I can say, titleis equal to a title. And basically, what I'msaying is this title up here, the title ofthe object is going to be equal to the titlethat they passed in. So whenever we createa new book, now we're going to pass in a title.And down here, I'm going to say that the titleof the object is going to be equal to a title.And so now instead of having to say like book,one dot title is equal to whatever. Now Ican just pass the title in over here. AndI'll just assign the title from over here.So essentially, doing this is the same assaying book one dot title is equal to whatever,it's the same exact thing, except I can justdo it straight from in here. So what we wantto do is do this for each of these attributes.So I can say, author is equal to A author.And then we can say pages is equal to A pages.And I just want to point out, you can namethese whatever you want. So I can even namethis title if I wanted. Or I could name this,you know, whatever, it doesn't matter. I'mjust using a title, because it kind of showsthat this is the argument that got passedin. And it kind of distinguishes it from theactual attribute of the object, but you canname it whatever you want. Alright, so nowwhen we go back over to our program, you noticewe're getting errors here and it's basicallysaying There's no argument given that correspondsto the required formal parameter. In otherwords, hey, you need to pass in all this informationnow. So what I can do is I can take this informationfrom down here, and I can pass it into here.So I can pass in the title Harry Potter, Ican pass in the author, JK Rowling. And Ican pass in the number of pages 400. So insteadof having to do that manually, I can justget rid of all this. And now we have the samething. So I'm passing in the title, the authorand the number of pages. And then over herein the book, I'm taking those parameters thatgot passed in, and I'm assigning them to theattributes of the object. And that is supercool and super useful. So let's do the samething for Lord of the Rings, we can copy thispaste this bad boy up here. So I can get ridof all of this stuff now. And essentially,we have the same exact thing. So we went fromhaving eight lines of code to create thesetwo objects. So now we just have two linesof code one each, and we're passing in allof these different attributes. So this shouldactually work. And I'm going to go ahead andprove that to you. So I'm gonna say consoledot write line. And I'm going to go aheadand just print out like Book Two dot, I don'tknow title. And so you'll see that this attributegot set. So now I can run my program. Andwe get a Lord of the Rings. So it's doingexactly the same thing. Now, I also want toshow you if you want, you can modify any ofthese values. So I can technically come downhere and say book to title is equal to theHobbit. And now this is going to update booktwo's title. So now when we print it out,it's not going to be Lord of the Rings anymore,it's going to be the Hobbit. So that's kindof how this constructor works. And that constructoris super powerful. It's an amazing way forus to be able to create these objects reallyquickly. And I also do want to point out thatyou can have more than one constructor. SoI have this constructor book. And it takesa title and author and a number of pages.But if I wanted, I could just create anotherone. So I could say like public book. Andthis could take no parameters. And I'd stillbe able to do this. And so now I can havethat. And I'll still be able to create a bookjust by saying book, book three is equal tonew book. So now I'm able to create the booklike this with no parameters with no arguments.Or I can create the book with a bunch of arguments.So you can create as many of these constructorsas you want. And yeah, that's kind of thebasics of constructors, these are very powerfulwe want to do is just play around with these,right? I mean, as long as you understand what'sgoing on, like this constructor over hereis directly related to me saying book overhere, then you have like, have a good understandingof what these are. And this tutorial, I'mgoing to talk to you guys about object methodsin C sharp. An object method is basicallyjust a method that we can define inside ofour class that the objects of that class canuse to either find out information or modifyinformation about themselves. And object methodscan be very useful. So I'm going to show youguys just a little demonstration on how touse them in this tutorial, what I've actuallydone is I've created another class in my program.So I created this student class over here.And this student class is pretty simple. Ijust defined three attributes that are goingto be part of my student class. So every studentis going to have a name, a major and a GPA.And then down here, I have a constructor.So I'm just sort of passing in the name, themajor in the GPA, and I'm assigning them downhere. So this is a very simple class, a lotlike the class we created in the last tutorialwith constructors. So now that I have thisstudent class, I went over to my program,and I actually created a couple students.So I had these variables, student one andstudent two. And then I created these studentobjects. So one is his name is Jim. He's abusiness major, and he has a 2.8 GPA. Andthen we have Pam, she's an art major, andshe has a 3.6 GPA. So these are two objectsthat I've created from that student class.And I want to show you guys how we can puta method inside of that student class thatthese student objects can use to find outsome information, what I want to do is I wantto be able to figure out whether or not eachof these students is on the honor roll. Right?So let's say that we're, you know, modelingstudents for a college or university and therules that that college or that if you havea GPA of 3.5, or greater than you have honors,so you're on the honor roll, I want to beable to find out whether or not Pam and Jimare on the honor roll really easily. So oneway I can do that is by creating an objectmethod. So what I'm going to do is I'm goingto come over here to my class, and down belowthis constructor, I'm going to create a method.So I'm actually going to create a method thatis going to tell us whether or not the studenthas honors. So I'm gonna come down here AndI'm just going to say public. And I'm gonnasay bool. Because we're going to return aboolean value. Essentially, this method isgoing to return a true if the student hashonors, or it's going to return false if thestudent doesn't have honors. So now I'm justgoing to call this has honors. And I'm goingto make an open and close parentheses, andan open and closed curly bracket. So insideof here, we can start writing out the codeto tell if a student has honors. Now remember,what I said before was, if a student has aGPA of 3.5 or above, that means they're onthe honor roll. So what I can do is I canjust use a simple if statement. And I canjust say if, and I'll come down here, andI'll just say, if GPA is greater than or equalto 3.5, then I'm going to come over here,and I'm basically going to return true. SoI'm just going to return true. And if that'snot the case, then I'll come down here andwe'll just return false. So in the case thatthe GPA is greater than 3.5, we'll hit thisline of code, which is telling us to returntrue, and we'll exit the method. And if thisis false, so if the GPA isn't greater than3.5, then we'll come down here and returnfalse. So this is obviously a very simplemethod, but it's going to come in handy withour objects. So I'm going to head back overhere. And basically, what I can do now isI can figure out whether student one or studenttwo is on the honor roll. So I can come downhere and I can just print this out. So I'llsay console writeline. And what I want todo is I want to print out whether or not eachof these students has honors. So I'm actuallygoing to copy this and I'll come over hereand I'll say, student, one dot has honors.And then we can also say, student two dothas honors. Alright, so I'm printing out ifwhether or not student one has honors, andI'm printing out whether or not student twohas honors. Now, what should happen is studentone dot has honors should return false becauseJim has a 2.8 GPA. Jim's not that smart. Andthis line down here, student two dot has honorsshould return true because Pam has a 3.6 Pam'spretty smart. So let's go ahead and run ourprogram. And we'll see what happens. So you'llsee over here, we got exactly what we thoughtwe would we got false and true. Now one ofthe cool things about the method that we wroteover here in this student class is that thismethod is actually going to use differentinformation depending on what object is callingit. So when the gym object calls it, whenstudent one calls it, it's going to use Jim'sGPA. So when Jim calls this method, it's goingto use Jim's GPA of a 2.8. When Pam callsthis method, when that Pam object calls it,it's going to use Pam's GPA of 3.6. So wecan specify one method here, we only needto write at one time, and the different objectswill be able to use it, and they'll be ableto use it with their own information. So Jimcalls this method and uses his GPA. Pam callsthis method and uses her GPA. And that's whythese methods can be so powerful, becausewe can define one method and then differentobjects that can use it. And they can getdifferent information back depending on thevalue of their attributes. Another cool thingabout this method is if I ever wanted to changethe qualification for honors, so let's saythat I wanted to change honors from being3.5 to being 2.5. So now I'm saying any studentwho has a 2.5 or above can have honors, well,now, I only had to change the code right here.And when I run this program, again, now they'reboth going to have honors. So that value isgoing to be automatically updated for bothof these objects, just by changing it in thatone spot. And that's what's so powerful aboutthese methods is they basically allow me todefine different rules for my object. So like,I can define what it means to have honorsin my program. And I can change it aroundif I want. And it's not really going to matter,because the objects are just calling thismethod, and it's telling them whether or notthey have honors. So that's why this is useful.And in the next couple videos, we're goingto be looking at some other ways that we canuse some methods just like this. But basically,all you need to know is that you can makeas many of these as you want, right? So Ican make a method over here that tells mewhether or not, you know, specific rule sothat I could it could tell me whether or notthe students have honors, I could also makea method that would modify one of these values.So nothing is stopping me from coming in hereand saying GPA is equal to 90.4. Right? Icould modify each of these students GPA, ifI wanted to, you can basically do anythingyou would do in a normal method. So play aroundwith these, you know, I'm sure you can thinkof a couple of different, you know, methodsthat you can create inside of your classes.They can be really awesome. In this tutorial,I'm going to talk to you guys about usinggetters and setters in C sharp. Now a getterand a setter are basically two types of methodsthat we can define inside of our C sharp classes,which will essentially control the accessthat people have to the attributes of thoseclasses. And essentially, what this does isit kind of like makes your classes more secure.So it kind of allows you to define like, whatdata is valid for specific attributes andwhat data is invalid. And really getters andsetters are extremely useful. And there'sa lot of different scenarios where you wantto use them. And this tutorial, I'm goingto show you guys one specific scenario, we'regoing to talk about, like how to set theseup, and essentially just how they work. Sowhat I've done in preparation for this tutorialis I actually created another class, it'sthis movie class over here. And this movieclass is very simple. It's basically justmodeling a movie inside of our program. Sothis is sort of like, you know, the templatefor the movie data type. And I said that everymovie is going to have a title, a directorand a rating. And then down here, I createdthis constructor where I basically pass ina title, a director and a rating. And I assignedall of those values. So this is a very simpleclass. And you know, like I said, it's justmodeling a basic movie. And then over herein my program, I created two movies. So Ihave one called Avengers, and it's just theAvengers with director, john Sweden, and it'spG 13. And then we have Shrek with directorAdam Adamson. And it's rated PG. So prettysimple program, right? We're basically justcreating a couple of different movies. Buthere's one of the problems that we actuallyhave with this program. And it might not besuper obvious right away. But the problemhas to do with the movie rating. Right? Nowgenerally, when movies have ratings, theycan only have specific ratings, right? Soif we have a movie, like generally, it's onlygoing to be able to be G, PG, PG, 13, R, ornr, right. And maybe there's some more ratings,whatever. But let's just say that these areall the valid ratings that we can have fora movie. So movie can either be rated G, PG,PG, 13, R, or nr four not rated. And let'ssay that we want to enforce these rules insideof this movie class. So we want all the moviesin our programs to only be able to have oneof these ratings, and it can't have a rating,other than the ones that I specified downhere, right? Well, the problem is, how dowe enforce something like that? Right, becausewhat I could do is I could easily come overhere and change the rating of Avengers todog for example. And now if I was to comedown here and print out the Avengers rating,for example, if I came down here is that consoledot write line, Avengers dot rating, whenI print this out, it's actually going to printout the rating. So it's going to be able toprint out dog. So dog was the rating thatwe gave to it. But dog isn't one of the validratings down here. Another thing I could dois even if I set this to pG 13, over here,so if this was like set to pG 13, I couldstill come over here and manually set it.So I could still say like, Avengers dot rating,is equal to, you know, dog over here, andit's going to be the same scenario, right?I'm still able to set this value equal todog. So what I want to show you guys is howwe can prevent this from happening. In otherwords, how can we make it so that the onlypossible ratings for the movies are one ofthese five ratings that I defined down here,we can actually use something called gettersand setters. And in order to use these gettersand setters, we're gonna have to modify acouple things. So the first thing that wewant to do is we want to close off accessto this rating property, this rating attributeand what I can do is I can actually come overhere into my program. And you'll see thatall of these attributes are public. So wehave public title, public director and publicrating. And I haven't really talked aboutthis too much yet. But public essentiallymeans that these can be accessed by anyone.So any other program, any other code thatwe're dealing with can access any of theseattributes. So public just means it's opento everybody. It's open to the world. Butthere's actually another modifier that wecan put in front of here. And instead of sayingpublic, I could say private. And what thismeans when I say private, this means thatonly code inside of this movie class is goingto be able to access the rating. So only codethat is contained inside of these curly bracketsover here in this out of this movie classis going to be able to access this and you'llsee now when I go over to program, I'm gettingan error down here. So essentially, what thisis saying is we can't access the rating becauseit's private. So because the code over hereis inside of the program class, and it's notinside of the movie class. It's not goingto be able to access the rating. So That'sthe first step in being able to enforce theseratings is we need to make the rating fieldprivate. So I need to cut off access fromanybody else. Now, the next thing I want todo is I want to create two things called gettersand setters. So we're going to create gettersand setters for this rating attribute. Andbasically, what these are going to allow usto do is it's going to allow outside code,for example, the code inside of this programclass like down here, it's going to allowcode like this to both access the rating,and modify and set the rating. So those gettersand setters are going to be really important.And we can define those through what are calledproperties. And a property is basically justlike it's kind of like a little method. Butit's a special method that's going to basicallyallow us to define a getter and setter. Sowhat I want to do is I can just say public,and I can just say string. And what I wantto do is name this, generally, what you'regoing to do is you're going to name it thesame as the attribute over here, but in capitalletters. So I'll name this public string rating.And then down here, I'm going to make an openand close curly bracket. And inside of here,I need to define two things or I don't needto, but I'm going to define two things. SoI can just say, Get an on make an open andclose curly bracket. And then I'm going tosay set, and I'm going to make an open andclose curly bracket. And these are essentiallygoing to be getters and setters. So a getteris going to allow us to get the rating attribute.And notice over here, I'm trying to get thisrating attribute by saying Avengers dot rating,but I'm not able to do it right, I can't actuallyaccess this rating, because it's private.And so the job of the getter is to give methat. So I'm just gonna come over here andinside this get, we're just going to say,return rating, and I'm going to put a semicolonthere. And so basically, whenever we say ratingnow, and we want to get it, it's going toreturn the rating. Now this setter is goingto allow us to set the rating, so it's goingto allow me to modify the rating. So if Icame over here and said, Avengers dot rating,and you can already see it's trying to makeme use this capital letter is equal to dog,it's gonna yell at me, because this is a privateattribute. So it's not going to let me dothat. And that's what the that's the pointof this setter, the setter is basically goingto allow me to do that. So what I can do inthis setter, though, is I can define a specificrule. So I can basically say like, Hey, youcan only set this value to be a certain value.And so what I want to do is I want to checkto see if the value is one of the valid ratings.And if it is, if the value they're tryingto set rating to is one of the valid ratings,then we're going to go ahead and set it otherwise,we're just going to do something else. SoI want to say if and I want to check to seeif the value that they passed in. In otherwords, the value that they're trying to setto rating is equal to one of the valid rating.So what we can actually do is we can say ifthe value and value is going to representwhatever got passed in, so value is goingto represent whatever they're trying to setthe rating to. So I can say if value is equalto and we're just going to do one for allof these. So if the value is equal to G, orvalue is equal to PG, and I'm going to dothis one for each of the valid ratings, soI can just say or value is equal to, and overhere, we can just put pG 13. So I'm gonnasay pG 13. And we're just going to do twomore so value is equal to R. And then thelast one is going to be for nr. So n overhere, I'll say or value is equal to an R.So if it's equal to one of these, in otherwords, if the value that we pass in is equalto one of these, then we're going to be ableto just set that is the rating. So I can justsay, rating is equal to value. Otherwise,though, I'm just gonna set the rating equalto nr, so I'm just gonna say rating is equalto nr. So they add in an invalid rating. Inother words, they add in a rating, they tryto set this to a rating that's not G, PG,PG, 13, R or nr, then it's just going to getset to not rated by default. So this getteris going to allow us to get the rating andthis setter is going to allow us to set therating. But you'll notice that in order toset the rating, we have to go through thisif statement, right? So they can try to passin whatever rating they want. But if it'snot equal to G, PG, PG, 13, etc, then it'sjust going to get set equal to not rating.And the reason we needed these getters andsetters was because we made this guy up hereprivate. So there's one more thing we haveto do in order to make this super secure.In other words, there's one more thing thatwe have to do to make sure that the ratingis on Sent to one of these values up herein my constructor, when I set the rating righthere, I'm just assigning it a normal value.So technically, the user could pass in whateverrating they wanted over here. And then I'mjust gonna set it to the rating. But now instead,I'm just gonna say rating is equal to A rating.And what this means is now we're going toset the rating through this setter down here,when I use this capital R, it's essentiallycalling this setter down here and settingit that way. So now this is completely secure.And down here, what I can do now is I canset this to whatever I want, and it's goingto be safe. So down here, I can say Avengersdot rating. So I'm using this capital R now.And over here, if I wanted, I could pass inan invalid rating. So I could pass in likedog over here. And when I print it out, you'llsee that we're going to get an R, so we'renot going to get dog, we're actually goingto get n r. And that's because we had to gothrough that setup. And the same goes foranything else. So I could say down here, likeShrek dot rating is equal to cat. And if wetried to print out Shrek dot rating, thenwe're going to get an R because it's goingto get filtered out by that center. But here'sthe thing, if I wanted to set this to a validrating, like if I set Shrek dot rating equalto R, now it's going to be able to take thatrating, because it's valid. So that's kindof how we can use getters and setters. Anda lot of times what people will do is they'llcreate getters and setters for each of theattributes inside of their classes, you don'thave to, but a lot of times they can be useful.So we want to do is just play around withthat. And, you know, basically, these justmake your class more secure. So they makeit so someone couldn't, for example, giveyour movie in invalid rating. In this tutorial,I want to talk to you guys about static attributesin classes in C sharp, a static attributeis basically a special type of attribute ina class, which is shared by all of the objectsand all the instances of that class. So astatic attribute is technically an attributethat is contained on the class itself, insteadof on the individual objects of that class.And I'm going to sort of explain to you howthis works. Over here in my program, I actuallycreated a class, and it's called song. Andthis class basically just models a song inour program. So it's kind of like a blueprintfor what a song should be in our program.songs have a title and artist and a duration.And then down here, I just have this basicconstructor, which allows the caller to createthe object right up front. So over here inmy program, I created two songs. One's calledholiday one's called cashmere. This is holidayby Green Day, and I just had it was 200 seconds.And then Kashmir by Led Zeppelin, 150 seconds.So we have our two song objects. And I wantto show you guys how we can actually createa static attribute on this song class. Soone thing I want to point out is there's thesenormal attributes that we have over here onthis song class, like the title, the artistand the duration, if I was to come down hereand print these out, so for example, I cancome down here and I can print out holidaydot title. And then right after it, I couldalso print out cashmere dot title. And ifI was to do this, you'll notice that bothof these objects have different titles. Sothe first objects title is holiday. The secondis cashmere, I could do the same thing forthe other attributes. So if I came down hereand said, holiday dot artists, and cashmeredot artists, they're gonna have differentartists, right. In other words, there's twodifferent values that are assigned to theattributes of those objects, right. So whenI create an object in my program, on basicallyallowing it to have its own title, its ownartist and its own duration. So each individualobject will have their own title, their ownartists and their own duration, right? Thosethings are going to differ across all of theobjects. And that is what we would considera normal attribute. But there's another typeof attribute which is called a static attribute.And a static attribute is an attribute thatisn't unique to each one of the objects. Inother words, a static attribute is an attributeabout the actual class. So this title attribute,like I said, it's different for each of theobjects. So holiday dot title, and cashmeredot title, those are different values. Buta static attribute is going to be the sameacross all of the objects of a class. In fact,a static attribute is basically just an attributethat we would say is about the class. So letme show you guys. Basically what this is I'mgoing to come down here and I'm going to createa static attribute. You can create it similarto these ones, I can just say public static.So I'm using this static keyword here. Andthen I'm going to give it a type and I'm justgoing to call it Song count. And basicallywhat this variable is going to do is it'sgoing to tell us how many song objects havebeen created. So I'm just going to set thisequal to zero initially. So I'm giving itan initial value. Now I want to show you guyswhat we can actually do with this static variable.Because we have this static attribute, I canactually come over here. And instead of sayinglike holiday dot artist, I can actually say,song dot song count. And I could actuallyprint this out. So I'm going to print thisout. And you'll see that we should just getzero, because that's what I set it to initially.So unlike the artists, the title and the duration,the song count attribute is actually on thisclass. So I couldn't say song, title. Becausetitle isn't an attribute that's associatedwith song, you'll see down here we're gettingthis error, I couldn't say song dot artist,because artist is going to apply to the objectsof the class, not the class itself. But Ican say song dot song count, because thisis a static attribute, which is, which meansit belongs to the class. So that's kind ofthe difference. And I want to show you guyssomething that we could actually do. So overhere, I have my constructor, right? This isa constructor method. It's a very simple constructor.Anytime that we create a song object. So anytimea song object gets created, this method getscalled it's a guarantee, right? Basically,when I come over here, and I say, new song,this is me calling that constructor. So anytimewe create one of these songs, it's going toget called. So what I'm going to do down hereis every time we create a song, in other words,after all this code in the constructor, I'mjust going to increment the song count. SoI'm going to say, song count plus plus. Sobasically, what's going to happen is, everysingle time a song object gets created, thesong count is going to get incremented. Solet me show you guys how this is gonna workover here, I'm actually just going to, I'mgoing to get rid of this guy. And I'm goingto copy this and I'm going to go ahead andpaste it in between here. So in between hotthe creating holiday and creating cashmere,we're printing out the song count. So let'ssee what happens, what we should get is onein two. So basically, when we create holiday,and then we print out the song count, onesong has been created, so we get a one overhere, then we create this cashmere object.And so that song count is going to get incrementedagain, and here we get to. So this staticattribute is telling us information not aboutthe specific objects themselves, but aboutthe class in general, right. So I can figureout how many objects have been created ofthe song class, right? How many instancesof the song class have been created in myprogram, but that's not a piece of informationthat is going to be specific to the holidayobject or to the cashmere object, that isa piece of information that's going to bespecific to the class itself. And that's basicallywhat a static class attribute is, it's anattribute about the class not about the specificobjects of the class. So it's basically anattribute that we store to kind of, you know,give us information about that class. Andyou can create static attributes, you cancreate as many as you want. And honestly,they can be really useful. And you'll noticethat whenever we access them, we don't saylike, I wouldn't say like cashmere dot songcow, like, I'm not going to be able to dothat. So we have to access it through theactual class. Now, one thing that we coulddo is we could create a method. So I couldcome over here and I could create a method.So I could say, like, public get song count.And actually, this is going to return an integer.And then over here, I could actually returnthe song count. So I could say like, and nowwe're actually going to be able to accessthe song count on each of our individual objects.So I could technically come down here andsay, cashmere dot get song count. And nowwe'll be able to get the song count off ofone of those objects. So you'll see now thatwe can get to just like we did before. Soyou can either just create a static attributeand access it using like song dot song countlike I did over here, or you could createa getter method like get song count, and thenthe individual objects could access that.And both of those can be pretty useful. Sometimesyou're gonna want the objects to be able tohave access to those static attributes. Butthat's sort of an overview of static attributesand really that static keyword. Actually,as we go forward, I'm going to show you someother cool stuff we can do with that statickeyword. In this tutorial, I'm gonna showyou guys how to use static methods in classes.A static method is basically just a methodthat belongs to the class itself. So a lotof times when We create methods inside ofour C sharp classes. Usually those methodswill be used on objects. So we can have anobject of a specific class and then that objectcan use those methods to, you know, do differentthings. But a static method in a class isa method that belongs to the actual class,which means you don't have to create an objectof that class in order to use it and accessit. And these can be extremely useful. Andthere's a lot of circumstances where you'dwant to create classes that have static methodsinside of them. So I'm going to show you guysbasically how that works. Down here, you'llsee that I have this little line, it justsays console dot write line. And then overhere, I'm saying a math dot square root 144.Right? Essentially, what's happening hereis there's this class in C sharp, which iscalled math. And inside of that math class,there's a bunch of these methods. Now onething you'll notice here, when I went to accessthis square root method, inside the math class,I didn't have to create an instance of themath class. And normally up to this pointin the course, whenever we wanted to use aclass, or use any of the functionality thata class described, we had to create an object.So I would have to say, like math, my mathis equal to new math, right, I'd have to createan actual instance of the math class likethat. But you'll notice that down here, Ididn't have to do that, right. In fact, whenI try to create an instance of the math class,I'm getting this error over here. So downhere, I can basically just say, math dot squareroot. And I'm able to use this method withouthaving to create an instance of the math class.And this is an example of a static method.So a static method, like I said, it's a methodthat belongs to the class, which means wedon't have to create an instance of the classin order to use it. So I can go ahead andrun this program, and we should get back thesquare root of 144. So we should get back12. I'm going to show you guys how we cando this, and how we can basically create somethingsimilar to the math class. So up here, I'mgoing to create a new class. And you can eithercome over here, right click, and go to add,and then click New Item. Or we can also goup here, and we can click project and clickAdd class. So I'm going to do it this way.Then over here, you can see I'm just clickingon class. And why don't we just call thisuseful tools. So this is going to be our usefultools class. And you'll see over here thatI basically just have class useful tools.And inside of this class, if I wanted to createstatic methods, all I have to do is come downhere and I can just say, like, public static,and I can create a method. So why don't wecreate one called Say hi, and it's going totake one parameter, so it's going to takea string name. And then we will basicallyjust have this Say hi. So it's going to consoledot, write line. And we're just going to printout Hello, name. And actually, whoops, forgotto put a return type here. So this shouldbe void. So public static void, say, Hi stringname, and it just prints out hello to whatevername gets passed in extremely simple methodover there. So what I could do is I couldactually come down here, and I could accessthat method directly without creating an instanceof the useful tools class. So down here, Ican just get rid of this. And we can justgo ahead and call this directly. So I couldsay, useful tools dot, say hi. So I didn'tactually have to create an instance of theuseful tools class, all I all I did was justaccess this method directly. So I can passin my name, like Mike. And now we'll be ableto run this method without having to createan instance of the useful tools class, youcan see over there, everything's running justfine. Now, this is an extremely useful thing.So what you could actually do is you couldcreate a class over here, and it could justbe contained of, you know, these static methods.And that's essentially what that math classesthat we looked at before, the math class isbasically just a class that has a bunch ofthese static methods inside of it, that areused to do different things. So if you justhave a normal class, you know, maybe a classthat's modeling some sort of real world entity,you can include static methods inside of there.And then the callers don't have to createinstances of that class in order to use them.Another thing you could do is set up a classthat is solely designed for this purpose.So for example, that math class, that mathclass is actually what's called a static class.So you'll notice when I tried to create ainstance of that math class before I said,like math, my math is equal to new math, I'mnot actually able to create an instance ofthe math class, you'll see I'm getting anerror here. And this is because the math classis a static class, which means you can't createan instance of it. But you'll notice withthese useful tools class I can create an instanceof it And it's going to be no problem. Solike this is actually like a useful toolsobject. So in certain circumstances, you'regoing to want to do that like, you're goingto want to be able to have a class with staticmethods that can have an object created ofit. But in situations like with that mathclass, you're not going to want to do that.So what you can do is you can come over here,and we could just say, static class usefultools. And now we're not going to be ableto create an instance of the useful toolsclass, you'll see down here, I'm getting thiserror, and basically says, cannot declarea variable of static type useful tools. Andthen over here, it says, cannot create aninstance of the static class useful tools.So that's sort of like two different waysthat you can use this. But these static methodsare extremely useful. And like I said, there'sa lot of situations where you're going towant to use them, basically, just to definefunctionality on the class level instead ofon the individual object level. In this tutorial,I'm going to talk to you guys about inheritancein C sharp. Now, inheritance is basicallya technique that we can use in C sharp, wherewe can have one class inherit all of the functionalityof another class. So I'm going to find somethingcalled a superclass. And then I can actuallycreate classes that are going to inherit allthe functionality from that superclass calledsubclasses. So I'm just going to give youguys a very basic introduction into inheritance.This is a huge subject, and there's a lotthat you can kind of get into with inheritance.So I just want to show you guys like the basicconcept of what's happening with it. So overhere, in my program, I created a class, it'scalled chef.cs. And this is a class that basicallylike represents a chef in our program. Soyou can see here, class chef, and this chefhas three methods that it can use. So thefirst one here is called make chicken. Andbasically all this does is it prints out,the chef makes chicken Right, so the chefcan make chicken, the chef can also make salad.So it says the chef makes salad and the chefcan also make a special dish. So it just saysthe chef makes barbecue ribs. So this is ayou know, a pretty cool class. It's obviouslya very simple class, but it's, you know, itcan basically represent a chef in our program.So down here in my program.cs, in my mainmethod, I created a chef object, and it'sjust called chef. And then I basically justsaid chef dot make chicken. So I'm tellingthe chef to make some chicken. And when Irun my program, now, it's going to say thechef makes chicken, right. So hopefully thatmakes sense. You know, I just have this chefclass over here. And I defined some methodsin there. And then I created an object ofthe chef class and told it to make chicken.Now I want to show you guys how we can useinheritance to make a nother type of class.So let's say that in addition to having justa normal chef, like we defined over here,I also wanted to have a more specialized typeof chef. So I wanted to represent not justnot only just a general chef in my program,but also a more specialized chef. So let'ssay I come up here, I'm going to say project,add class. And I'm going to create a classcalled Italian chef. So a Italian chef isnot just going to be a normal chef, he's goingto be a Italian chef. And I'm gonna go aheadand create this class. So you'll see overhere we have this class Italian chef. Now,let's say that this Italian chef can do everythingthat the normal chef could do. Right. So thisItalian chef is a really awesome chef. Andnot only can he just cook regular food, buthe can also cook like more specifically Italianfood. So let's say the Italian chef can doeverything that the normal chef can do. Sothe Italian chef can also make chicken, theItalian chef can also make salad. And theItalian chef can also make a special dish.So the Italian chef is very similar to thenormal chef, right, you can do everythingthat the normal chef can do, you can alsodo some other stuff as well. One thing I coulddo to give the Italian chef all of this functionalityis I could just copy. And I can paste allof these methods over here, right. And sonow the Italian chef is able to make chickenable to make salad and able to make a specialdish, right. But in C sharp, there's actuallysomething that we can do in a situation likethis. So anytime you have a class, like Italianchef that can do everything. And that hasall the same functionality and attributesas another class, like this chef class, wecan use something called inheritance. Andinheritance is basically the process of inheritingall of the functionality, all the attributes,etc. From a class like chef into a class likeItalian chef. So what I can do is I can comeover here and I can say Italian chef and Ican make a colon. And I can just say chef,and basically what this means is that theItalian chef is going to inherit all the functionalityfrom the chef class. So now the Italian chefcan Do everything that the chef class cando. And I'm gonna come over here and provethat to you guys. So I'm going to create anItalian chef object. So I'm just going tocopy this guy. And I'm going to paste thisdown here. And I'm just going to change everythingto Italian chef. So I went ahead and changethis to Italian chef, it's called Italianchef. And we said, new Italian chef. And nowI'm saying Italian chef dot make chicken,now, on some calling them make chicken methodon the Italian chef objects. But you'll noticeover here in the Italian chef class declaration,I don't actually have any methods specified.So I didn't specify like a make chicken methodor anything like that. But what you'll seeis because I inherited all of the functionalityfrom the chef class, I'm actually still ableto make chicken with the Italian chef. Sowhen I run my program, you'll see that itsays, The chef makes chicken. And this isthat normal chef. And then down here, theItalian chef is also able to make chicken,because the Italian chef inherited all thefunctionality from the normal chef. And that'skind of cool. So that's basically what youcan do. If you have like two classes. Andin C sharp, we will refer to chef as the superclass.And we would refer to Italian chef as thesubclass. And the subclass is always goingto be inheriting functionality from the superclass.So that's just a little terminology. Now wecan actually take this a step further. Solet's say that the Italian chef, in additionto being able to make chicken salad and aspecial dish, can also do something else.So we could add another method in here, Icould say like public void, and we'll justcall this like make pasta. So in additionto making all that other stuff, the Italianchef can also make pasta. So now this chefcan also make pasta and forgot to put an openand closed parentheses there. So if I wasto come over here to my program, I could sayItalian chef dot make pasta, and the Italianchef is going to be able to make pasta. Solet's run that. And you'll see over here,he's making pasta. But what you'll noticeis this normal chef can't make pasta. So ifI tried to make pasta on the normal chef,it's not going to be able to do that. So that'sgonna throw an error. And that's because weonly define make pasta in the subclass, notin the superclass. So that's kind of how that'sgoing to work out. And I want to show youguys one more thing we can do. So you'll noticeover here in my chef class, I have this method,it's called make special dish, right. Andthe chef is making a special dish of barbecueribs, right. So this chef's special dish isgoing to be barbecue ribs. But let's say thatthe Italian chef doesn't want to make barbecueribs as a special dish. So let's say thatthe Italian chef's special dish is actuallylike some other type of dish, and it's nota barbecue dish. Well, the problem is whenI come over here, and I say, make specialdish, and I say, make special dish, both ofthese chefs are going to be making the samespecial dish. So when I run the program, they'reboth making barbecue ribs. But remember, Idon't want the Italian chef to make barbecueribs, I want the Italian chef to make somethingelse as their special dish. Well, in a situationlike this, I can do something called overridinga method. overriding a method basically meansthat I take one of the methods that I've inheritedlike this make special dish method, and Ioverride it. So I basically come over hereinto this Italian chef class. And I overridethe functionality of that method. Now in orderto do this, we're going to have to do onething over here in the chef class. And we'regoing to have to include this virtual keyword.So you'll notice I already have this in here.So up here on these two methods, it says publicvoid make chicken public void make salad.But down here on make special dish, I've givenit this special keyword, public virtual voidmake special dish. And when we specify thisas virtual, basically, that means that thismethod can be overridden in any subclasses.So when I say virtual, it basically meansthat subclasses can change the functionalityof this method. So I can just copy this method.And I'm just going to go ahead and paste itdown here. And you'll see here I'm sayingpublic virtual void make special dish, butinstead of saying virtual here in the subclass,so I'm in my Italian chef class, I'm gonnasay, override, and this is basically tellingC sharp that we're going to override the makespecial dish method from the superclass, andthen down here, I can change it so I couldsay the chef makes instead of barbecue ribs,why don't we say like chicken parm. And sonow when the Italian chef makes a specialdish, it's going to be making chicken parminstead of making barbecue ribs. So let'sgo over here into our program. And you'llsee I'm still printing out chef dot make specialdish and Italian chef dot make special dishwhen I run the pro They're printing out differentspecial dishes. So the Italian chef successfullyoverrode the functionality of one of the methodsthat it inherited from the superclass. Andthat is extremely useful. So those are threevery core concepts in inheritance. So thefirst is just inheriting all the functionalityfrom a superclass. The second is extendingthat functionality. So for example, in additionto being able to do everything that the normalchef could do, the Italian chef could alsomake pasta. And then finally, we were ableto override one of the functions or one ofthe methods that we inherited using this overridekeyword on the subclass, and using this virtualkeyword on the superclass. So that is sortof the basics of inheritance. And like I said,there's, you know, inheritance is a very complexsubject, and there's a lot lot lot of stuffthat you can do with it. But this is kindof just an overview of essentially how itworks. So now you kind of have the conceptsdown in your mind and you can kind of go forwardand learn more specific ways to use it. Hey,thanks for watching. If you enjoyed the video,please leave a like and subscribe.\n"