Transcripts
1. Introduction: Hey everybody, my name is Jill the data and welcome to my C-Sharp course for beginners. Now, why should you learn C sharp in the first place? Well, first off, they can jumpstart your career because it is one of the highest in-demand programming languages with the average annual salary for a C-sharp programmer being a $100 thousand plus. Also, it is a very versatile language used to make video games, mobile apps, websites, desktop applications, and a whole lot more. Also, it was created and is backed by Microsoft. So it's not going anywhere, anytime soon. And lastly, it is an object-oriented programming language based on the C language. And even if you don't know what that is, basically what I'm trying to tell you is that it is easy to transition from C-sharp to other languages like Java, indoor C Plus Plus. Now, why should you pick this course over the others? Well, first off, you can start this course with absolutely 0 programming knowledge. And by the end of it, you'll become a C-sharp programmer. Because not only do we covered the basic fundamentals in this course, but we also delve into some more advanced topics like Polymorphism, interfaces and inheritance. Also, there are no hidden fees. So all the programs that I use in this course, or a 100% free to download and use for life. And everything is broken down into very easily digestible, step-by-step, in-depth lessons so that you can easily follow along and learn on your own pace. And lastly, let me quickly talk about why I made this course in the first place. Well, when I was trying to become a programmer, things like college and coding boot camps were completely out of the question for me, just data the cost. Also, I spent a ton of time trying to find a course of video series or a book that resonated with me because it seemed like every time I thought I found something and ended up being something that was unfinished. Or it was just a cash grab for the content was really lacking in detail. Or it just tried throwing a ton at me at one. Plus when I would check out the comments section, I don't want to see a bunch of unanswered questions, which to me meant if I had any trouble, I named my questions, we're going to get injured either. So I thought to myself that needs to be a better way for aspiring programmers to learn to code. And it needs to be affordable, not cost hundreds or even thousands of dollars. And it needs to be in depth enough that people can truly understand the concepts being presented. And if they still can't figure it out, there needs to be a way for them to get answers, which is why I'm in this course here on skill share, so that I can talk to you guys and the discussion section, if you have any questions at all. Anyways, if you've decided that you want to jump start your career and really opened up the possibilities for yourself. Or you just want to learn programming that this course has you covered. So let's get started.
2. Chapter 1 (Setup): Install Visual Studio: In this video, I'm going to
be showing you how to install Visual Studio is a free program available on both
MacOS and Windows. So the first thing you're
going to want to do is look up Visual Studio on Google, and it should look
something like this. Now for those of you on MacOS, you're going to want to
click the button here that says Visual Studio for Mac. And then click on this
download button here. For the rest of you. While you're gonna wanna do is click here where
it says downloads. Find the one that
says Community, and click on the Free
Download button below. Once you do this,
it should start to install the program
automatically. So the next thing
you're going to want to do is go ahead and open that up. Hit Yes and or continue
on any prompts that pop up and then wait for
it to finish downloading. Once it is installed, it's going to ask you what workloads you want to download. If you're on MacOS, the one you want to
download as dotnet Core. Otherwise, for those
of you on Windows, you're going to want to
click on the one that says dotnet desktop development. Now, if you're interested in any of the other
workloads available, feel free to download them now. Otherwise, you can always
download them later by using the Visual
Studio Installer. Then once it is selected, go ahead and click Install and wait for it to
finish downloading. Once it has finished installing, go ahead and open it up. And then what you
wanna do is go ahead and create a new project. This portion of the video
has been updated for 2022. Now, after hitting
Create a new project, you should end up at a
screen that looks like this. And the easiest way to find the project type that we're
looking for this to go up here to the top where it says all languages and
click on C-sharp. Then we're gonna go with
the one that will run on Linux, MacOS, and Windows. So after you select that, go ahead and hit Next. Then we're going to want to
give our project a name. And you can name this
whatever you want. However, you'll want to use a Pascal Case naming convention. And to do that, all
you need to do is help the very first
letter is capitalized, and then every subsequent word, we'll start with a
capital letter as well. And you're going to have
no spaces in between. Now, if it's easier
for you to read and you would like spaces
between the words, then you'll want to use an
underscore because you don't want any actual spaces
in your project name. Anyways, go ahead and name
that whatever you want. Then go ahead and choose the location where you
want those to be saved. And you can leave it out
the default location, or you can click on these
three dots here to browse your files and choose a
location of your own. Then we're gonna
go ahead and leave the solution named the same. And if I mouse over this
information simply here, you can see that a solution
is a container for one or more projects
in Visual Studio. Now, because we are just
creating the one project, we're going to
keep things simple and leave the name the same. However, in the future, if you ever creating
a library of code, oftentimes you'll want these
to be different names. Then we'll also
want to make sure that this box here is unchecked. This as play solution
and project in the same directory as this is generally considered
good practice. Then we'll go ahead
and hit Next. And you should end up at a
screen that looks like this. Then we'll want to make
sure to check this box here that says do not use
top-level statements. Because if you do not do this, your code will not match mine throughout the
rest of the course. Then we'll go ahead
and hit Create. Once your project has been
created and has launched, it should look
something like this. So we've now installed
Visual Studio and created our very first
console application. So once you've
reached this point, you are ready for
the next video. Anyways. Thanks for watching, and I'll see you
in the next one.
3. Chapter 1 (Setup): Get Everyone On The Same Page: So before we get started with any actual programming, I just wanted to make sure that you are at the same starting fans I am. So what I'd like for you to do is start the program by either pressing livelier, keep hard, going up to the toolbar here at the top and clicking this button. Or by going to the debug drop-down menu at the top and clicking start debugging. This should launch the console application I want you to do is say Hello, welcome to the top. If it did, great, go ahead and press any button to close out this window or click the X at the top. Now think did work. Great, you don't do anything, just sit back and follow along. If it did not work. What I would like you to do is go to the debug menu again and click options. And under the debugging general settings all the way at the bottom, there should be a checkbox that says automatically close the console one P by being stops, make sure that as unchecked and then click OK. Now if you are using Visual Studio and you run the console application, it should stay open and he should be good to go. If you're not using Reginald studio, which I highly recommend that as a free program, this may not have worked and will explain well. So what is happening is computers written three lines of code from top to bottom, reaching the end and then thinking it must be done. So like I was heading closest down. This happens in Sydney and which is why you may or may not know this, the complexification popping up at all. So to prevent this, we are going to add our first line of code. And I'd like for you all to follow along here as this may be useful information for you at some point in the future. It's just good practice. So what you wanna do is create a new line on your console dot write line. You're gonna wanna type console with a capital C. So as you see in the lineup of the capital R, C, capital K, open and close parenthesis, semicolon at the end. What this line does is it basically tells our programs that we wanted to wait for any key on my keyboard. So now when we run our program, it should stay open. Remember you can do this by pressing f phi when your keyboard going up here and clicking this button at the top, or going to debug, drop down menu and clicking Start Debugging. Now what it is doing is printing hello world and waiting for any t and put before a closing. For now, just realize that for any who weren't experiencing problems, but you'll have to press any key twice instead of once to close out of this. Or you can always press the accepted time. Now if you are still happening and you're using Visual Studio, you'll want to check over your code and make sure it looks exactly like mine. Helium line gnomic, nor is this one here, this namespace as every unions your program and should not be changed. Then you'll want to make sure it's also the latest version. And I've promised at Albert. Otherwise, if you are not using Visual Studio, I can do suggest that you check your code and then check the trainee further issues you might be happening. Now, I'd like for all of you to go ahead and save something you wanna make sure you do at the end of each and every video. Well, you have to do is file here at the top and click Save All. Anyways to the zip for this video. And the next one we're going to look at our program. It go over exactly what it is we're looking at. Does what it does. So thanks for watching and I'll see you in the next one.
4. Chapter 2 (Hello World): Explaining The Program: And thus video we are going to go over all the code we have here in front of us. Now this stuff is a bit more advanced. So don't worry if you don't understand all of that right now, I just want to provide you with a bit of insight as to what is going on here. So that as you continue through the course, you can start to piece things together. So the very top here we have the text using system. What the states in a nutshell is that we are using code from the namespace system. A namespace as just what it sounds like. It's a named space in which our application resides. Below this, you can see that our application has its own namespace. This is based on whatever you named your project when you originally created it. This is something Visual Studio does by default. Basically all I want you to get from that as let a namespace is a way of organizing code. You can think of this as being the equivalent of a last name. Just those people whose last names as another way to distinguish one another. A namespace allows the computer and us another way to distinguish various groups of code by using this using system Director here at the top. We no longer have to use the full name when using code from this namespace, which I'll show you here in a bit. So back to my last name example, destructive at the top would be like starting a conversation about a family. Once I tell you their last name, I don't need to repeat who I am talking about as their first names are now going to be associated with the family and of which I am referring to. Next, we have a class called program. This is made for us by default when we make a new console application. Real quick, C-sharp as an object oriented programming language. And an object is an instance of the class. Now a class is something modeled after real-world object, and it is made up of variables and methods, which we'll get into later. So let's use a light bulb as an example. Imagine we wanted to make a light bulb class. It might contain a single variable that tells us whether it is on or off, as well as a single method for turning it on and off. Now, if we have a box of light bulbs, each one would be a different object or an instance of our light bulb class. Hopefully that analogy works for you. Anyways, back to our program here, we also have a single method called main. Every program needs is allowed, one main method, and this is where our program begins its execution. So when our program runs and runs the lines of code and our main method from top to bottom. Our first line here basically tells a program to print out the text between quotation marks onto a single line and our console application. And as you can see, when we run our program, that does exactly what it does. Now we also have this line of code here that we added in the last video. This tells our program that we want it to wait for some sort of key input before continuing. How does it know to do this? You may ask, well, let me tell you, just as we have our namespace with the class called program and a method called main. There is also a library of code with a namespace called system and a class called console, which contains both the right line and the red key methods. Now how do we not use this system here at the top? And like I said, you can think of this as sort of like a last name. We would have had to type system, console dot write, line, and then the rest of the text here. However, since we already have it here at the top, we no longer need to write it down here as it already understands where this console class is coming from. Now there's only really a few things I want you to really understand for right now so that you can continue throughout the course. One as that 99% of the code that we'll be writing is going to take place between these two curly brackets. And that this line at the bottom tells her program to wait for some sort of key input before continuing. I realize not all of you need this line of code, but it isn't going to hurt anything and it will be leaving it here and every program for those who do just to simplify things. In the next video will be both editing and writing new code in order to print whatever we want to the console. So thanks for watching and I'll see you in the next one.
5. Chapter 2 (Hello World): Writing To Console: In this video, we're going to be learning how to print text to the console. Now if you remember, I had mentioned that our console dot write line here, prints whatever is between these two quotation marks to the console on a single line. Now this is one of the two main ways you'll print text to the console. So let's start there. As we already know, this will print Hello World on a single line. And as essentially the equivalent of typing hello world exclamation point and a word document, and then pressing enter or return at the end. To prove this, let's go ahead and copy this line of code. Creates a new line below it, and paste it again. Then let's go ahead and run our console application. Remember you can do this by pressing F5, clicking this button here at the top, and we go into the debugger drop-down menu and clicking Start Debugging. Now as we predicted, you can see that it printed hello world on two separate lines and the cursor is at the bottom. Next thing we're going to do is edit this code. So let's go ahead and delete one of these lines of code. Then what you'll wanna do is delete the text here between the quotation marks and write whatever you want. I haven't run the console application again. And as you can see at us, printed but we typed on a single line. Now, what if you didn't want to print on a different line? At the moment, you might not see a reason for this, as you can always just add more text to the previous line of code. But later on when we start getting into user input, you'll see why this is useful. So let's go ahead and write a brand new line of code. So we'll create a new line on our console dot write line. Then we're going to type console with a capital C dot, right? With a capital W, open parenthesis, two quotation marks, and then close parentheses, and lastly, a semicolon. Every statement, also known as an action in c-sharp, either ends with a semicolon or a closed curly bracket. Depending on the weather is made up of a single line or a block of code containing multiple lines. If he worked forgot the semicolon at the end, you would get an error and your program wouldn't run. So let me go ahead and show you what that looks like. So as you can see, a says there were built errors and asked if I would like to revert back to the last successful build. I'm gonna go ahead and click now. Now at the bottom here is going to pop up any error codes and backup here, you can see that there's a red squiggly line where the code was detected. Now, there's a million different errors and C sharp, so I'd never be able to go over all of them with you. But if you ever do get an error, you can go ahead and copy and paste this Eric code until Google and look it up. And you shouldn't be able to find out what it means. Most of the time though it is probably because you misspelled something, didn't capitalize it properly or forgot to endless statement where you shadow. So I'm gonna go ahead and paste the semicolon back in. Anyways, enough about errors, let's go ahead and move on with the lesson. Now, as it stands, if I were to run my program and it's gonna print the very first line and then a blank line because I don't have any text between microbes. Now, let's go ahead and put some text between these codes and our console dot write statement. So forget to put whatever you want here. Then let's go ahead and run our console application. So as you may notice, or cursors setting out the end of our second line of code. Whereas before it was dropping to the bottom. This is because whereas the console dot write line method was equivalent to us typing text up in a Word document and hitting Enter at the end. A right method simply prints the text, leaving our cursor at the end. So let's go ahead and close that out. Next, let's go ahead and copy our console dot write method, create a new line below and paste it. Then we'll run our console application again. And as you may have expected at presented the same exact text right after the last. Notice that it doesn't help you out by adding any spaces or punctuation or showing you any problems with your text. It just does what it's told. So that is something you'll want to be mindful of. Anyways, let's go ahead and close this back out. And I'm gonna go ahead and erase our copied line. The console dot write line method and the console dot write method are the two main ways you'll be printing to console and C-Sharp. Lastly, when I'm working with a string in C sharp, which you can just think of as text. The backslash as a special escape character that basically tells her program that the next character is a special character where it should be taken literally. So let me give you an example of how this might be useful. So something you may not have thought about as typing a quotation mark, as it normally signifies the end of our text here. But by using the backslash and then a quotation mark, we can actually type a quotation mark, as you can see here. Notice that the backslash is not printed the console. Next, let's go for a female characters that you can put in here. First off, you can put two backslashes because the backslash is considered a special escape character. You need to type two. The second one tells our program that we actually want to print a backslash. And as you can see when I run the program, that's exactly what it does. Next, we have backslash, lowercase t. This tells our program that we want to insert a tap and or the equivalent of five spaces. And lastly, we have backslash, lowercase n, which says that we want to make a new line. If you are in macOS instead of Windows, this will be backslash r. Keep in mind that using the backslash or the special escape character only tells our program to check the very next character for another meeting. So when creating a new line in this way, putting a space after the end would cause your program to put a space on the brand new line, which is why I do not have a space between the N and the S on the word second. And either you can see when I run our program, it works just like a solid. Now I do understand that we could have just created a new console dot write line statement instead of using the backslash and to create a new line of code. But that could eventually get messy in terms of readability, especially when we start to work with bigger programs. And you always want to do everything you can to make your code is easy to read and as understandable as possible. So that you can not only understand and easily read it now, so that you could do the same tomorrow a week from now, a month, or even a year. And hopefully so that someone else could take a look at your code and understand it as well. This is a core concept in programming and something I want you to remember in practice as we continue throughout this course. Now, though, I do believe the following me along exactly will help when it comes to any mistakes you may have. I also understand we had type things might not always be the easiest for you to understand or visualize properly. So feel free to change things to your preferences a bit. But if it becomes an issue, I recommend just following along exactly for now. But later on when you create your own code that you can go ahead and change it up a bit. And the next couple of videos we'll be going over ways to help achieve readability by using comments and by utilizing whitespace. So thanks for watching, and I'll see you in the next one.
6. Chapter 2 (Hello World): White Space: In this video, we're going to be talking about whitespace now and the C sharp language spaces, tabs and new lines are all considered to be whitespace. And it is generally ignored when the program runs because the compiler or the thing that turns our code into the console application doesn't really care about whitespace. And this simply use to make the code more readable to you, the programmer. However, there are some exceptions to this case. Two of the main ones being names in strings of text. First things first, let's go ahead and erase this backslash n here. Then to show you an example of where whitespace does matter, go ahead and put a space between the NMDA as I'm a name console here. And as you can see, when I try and run the program, it gives me an error. Then the other is strings o texts. So like up here, all these spaces are going to be printed to the console. However, like I said, in most cases, spaces, tabs, and new lines are considered whitespace and are generally ignored when the program runs. So, for example, we can go ahead and create as many new lines as we would like in between our lines of code. And the program will run just fine. And just to prove what I was saying before, spaces and tabs are oscillating in art as you can see here. Like I said, the way space is just for your convenience to make your code as readable as possible for you. Now I'm gonna go ahead and show you a kind of ridiculous example of using whitespace just to show you that it does not make a difference. And as you can see, the program still runs just fine. Anyways, throughout the course, I encourage you to use whitespace here advantage and make your code as readable as possible. However, and assess becomes an issue. I encourage you to copy my text exactly until you become a little more comfortable with programming. Or just wait until after the course when you start to go on your own and make your own programs. And the next video we're going to go over another way to make your code more readable by using comments. So thanks for watching, and I'll see you in the next one.
7. Chapter 2 (Hello World): Comments: In this video, we'll be talking about comments, what they're for, and the syntax for them and how to write them. However, before we get started, I'd like you to go ahead and erase all the lines of code above our console.log statement. Then above our console.log statement. You're gonna go ahead and type console with a capital C, right line with a capital W and L. Open parenthesis. Quotation marks, close parentheses, and a semicolon at the end. Then, in between our quotation marks, I would like you to type hello with a capital H, space, world with a capital W. And I'll exclamation point at the end. Now though I encourage you to type out console dot write line for awhile just to get some practice in, I am going to show you a little trick. So go ahead and create a new line under our console dot write line statement. Go ahead and type C, W, and then press the tab button twice. And as you can see, it automatically puts in our console dot write line statement for us. And all we have to do is either quotation marks. This can save you a tremendous amount of time in the future. Anyways, let's go ahead and erase that. Anyways, back to comments. So a comment and programming is a section of code that has completely ignored when the program runs, sort of like whitespace. This was extremely helpful for explaining your code and for testing purposes. To turn a line into a comment, you simply want to put two forward slashes. So let's go ahead and do that. Let's create a new line above our console dot write line statement and forward slash, forward slash. This tells her program to ignore the rest of the code in front of it on this line. So for example, let's say we wanted to make with this line of code here does more obvious at a glance. You might type something like this. Print hello, world to console. As you may have noticed, this line of code here is a different color than the rest of the program, in this case being green in order to show that it is a comment. Another way to create a comment as the highlight, all of the lines of code you would like to come out. And then to go to the top and click this button here. You can also click on the button next to it to un-comment this selected lines. The last method I have for you is forward slash Asterisk, asterisk for its Lash. And this will ignore all the lines of code between the two asterisks symbols, allowing you to start an NDA comment wherever you would like, either on a single line or across multiple lines. To demonstrate this, let's go ahead and type a forward slash and an asterisk before our console dot write line statement. And as you can see, although the lines of code in front of it happening commented out. To end this, we will put another asterisk and afford slash. Let's go ahead and do this after console.log statement. And as you can see, all of the code after it is not commented out. Anyways, let's go ahead and undo that. So let me go ahead and show you how it is useful for testing purposes. So let's say that I wanted to see how my program would run without a line of code or if you were to run at all. Although I would have to do as comment it out instead of deleting it entirely. So for example, we had comment out our console dot write line statement here, and then run our program. And as you can see, when we run our program, there is no longer anything being printed to the console. And I'm going to go ahead and undo that. Anyways, what I'd like you to do is to make sure that code looks exactly like mine. And then when you're done, go ahead and save your program by going to file at the top and clicking Save. All remembered that day this after each and every video. And the next video, we're going to be going over what exactly variables are in programming and how to write them. So thanks for watching, and I'll see you in the next one.
8. Chapter 3 (Variables): Intro To Variables & Var Data Type: In this video, we'll be talking about variables, a variable and C-sharp as a name given to a storage area. So it stores data of a various type. In other words, it has a name we give to some type of data so that we can both referred to it and manipulate it in the future. So for example, let's say we are making a pinball game. We might want to store a whole number and call it score. The syntax for creating a new variable is as follows. It is the data type by the name. And lastly, a semicolon at the end. Now, there are multiple data types for storing all sorts of things, such as whole numbers, floating point numbers, single characters, strings of characters, and our text, true or false values and Mark will be going over all the basic ones individually in the upcoming videos. Next, let us get into some more examples and break down the syntax for declaring and initializing variables in different ways. For right now, we are going to use VAR for our data type. Var is short for variable And just means that we want the compiler to figure out what type of variable we need. For those of you who don't know what a compiler is. It is what turns our code here into binary so that the computer can understand it. As a computer only understands ones and zeros. Anyways, back to variables. So let's start by simply declaring a variable. To-do lists. Remember, we need to type the data type followed by the name. And lastly, a semicolon. So let's say we wanted to make a variable to hold our ammo count in an FPS, we might type something like this. Far space ammo count, and then a semicolon at the end. Now when you name your variables, there are some things you need to keep in mind. First, you want to make sure that you give it a descriptive name, not something generic like x. That will make your code harder to read. And when you start working with larger programs, you aren't going to remember what x means. So don't do it. You can't have any spaces in your variable names. However, you can use underscores as a decent substitute. Also, notice how he typed out ammo count. This way of typing is called CamelCase. This snake case are both accepted naming conventions and programming. Camelcase is where you have 0 spaces or punctuation. The first where it begins with a lowercase or uppercase. And any subsequent words begin with a capital letter. Snake cases similar, except you separate the words without underscore instead. Let me comment this out quick and show you what that would have looked like if her to use snake case. Here would look something like this. Anyways, I'm gonna go ahead and undo that. So you can use whatever you prefer, either chemical or snake case. But in this series, I'll be using CamelCase. And that's because it is more common. Then next thing to know about naming variables in C sharp is that there are special keywords that you can not use as names. Here's a list of them now. Now, don't get too overwhelmed by that as I've never run into an issue with any of them. And you shouldn't either as long as you are using descriptive themes. Plus, you'd get an error if you try to use any of them. Anyways, as we continue through the course, I will provide you with more proper naming conventions so that you'll learn to code properly. Now, back to our ammo variable. Let's go ahead and initialize it and are given a value to do this, all we have to do is put an equals sign the after the name followed by a value. Unless case, let's say RAM account to 30. Now, there is another way to declare and initialize variables, which I'll show you in the next lesson when we work with our very first datatype. Next, let's test and see that we actually created a variable called ammo count and set it equal to 30. Now, if you remember, one way to print the console is to use the console dot write line method. Also real quick, I'm gonna go ahead and move the console dot read keyed method down to the bottom of my program. Before we had used the console dot write line method to print text, as you can see above. But we can also use it to print out the value of our variable. So let's go ahead and do that. So under our new variable, will type console dot, write line, open parentheses, and then close parentheses. And lastly, semicolon. Now instead of putting quotation marks in here to signify that we are working with text, we can simply answer our variable name. Now what this plan will do is print the value of our ammo count variable on a single line. And as you can tell, when we run our program and doesn't need print 30. So let me quickly go of her is all happening here. So first we created a variable which sets aside a certain amount of memory based on the data type. Then we gave it a name so that we can access and modify it later. Next, we initialized it by saying that we want our variable or the name. We gave a storage area and memory to hold the value 30. Because we used fire hazard data type, the compiler automatically figured out what type of data type we actually needed based on this value, which is why it says it represents a 32-bit signed integer. We will get into integers more in the next video. Then, lastly, we went ahead and printed that value onto a single line in the console. Now, because we only implicitly told the compiler what data type to use, we had to initialize our variable on the same line. How do we explicitly told the compiler what data type we need IT? There would have been multiple ways to define and initialize our variable. We'll go over these other options in the next video when we talk about integers, a data type for storing whole numbers. Anyways, thanks for watching, and I'll see you in the next one.
9. Chapter 3 (Variables): Integers: In this video, we're going to be talking about integers. And integer is a data type for storing whole numbers. The two main ones you'll be using our Signed and Unsigned 32-bit integers. A 32-bit integer is abbreviated to end in C-sharp and will be referred to as such from here on out. Now to start things off, I want all of you to erase all of the code and your main method, except for our console dot read line. You guys don't have to write down the rest of those text here. I'm just going to leave it here as a reference for you guys. Now the difference between us signed and unsigned int as whether or not it can store a negative number or it go below 0. A signed int can go below 0. And an unsigned int cannot. You can think of it like this. If they were asking for permission and needed you to sign something, for it to go below 0. And you send now and didn't sign it, it would not be able to do so. So unsigned ints don't have permission to go below 0. And signed ends have permission to go below 0. And Sir signed by default and can normally store any whole number in this range here. And then unsigned and consider any number in this range. Which for those curious, is the same as adding the two numbers together from the signed end, assuming they're both positive. Now if you didn't need to store a larger hole number or only needed a smaller one. There's other integer types which I'll show you now. As you can see, there are multiple integer types that take up different amounts of memory, as well as have the ability to hold a various range of whole numbers. However, since they are less common and unnecessary in most cases, we aren't going to dive into them. And of course, I just wanted to make sure that you are aware that they exist just in case you were to ever see or meet them in the future. But most of the time, and it will work just fine. They are awesome, more efficient. Anyways, let's go over some examples of using ends. So in the last video, we worked solely withhold number variables. However, we left it up to the compiler to figure out what type we need it by implicitly saying what data type we needed by using the keyword var. Now we're going to explicitly do it. And this is what I'd recommend doing most of the time if able. So now that we are explicitly typing our variables, we can go ahead and declare them on one line and initialize them on another. So let's do that now by making it into a variable called score. So if you remember to declare a variable, all you have to do is type the datatype being int, followed by the name being score. Then lastly, a semicolon at the end to end our statement. Now you may have noticed this green squiggly line here on our variable name. And basically all these are just kind of a heads up. If we mouse over it, you can see that it says that the variable score as declared but never used. Now that your program will run just fine as is. Those are just letting you know that as of right now you don't technically need this variable. But as soon as we use the variable score for something, this will go away. Next, let's go ahead and initialize our variable on a separate line. To do this, all we have to do is type the name, followed by the equal sign or the assignment operator. Then a value. Let's go ahead and make this 20 followed by a semicolon at the end. Next, let's declare and initialize a variable on the same line, just as we did in the last video. So on a separate line, let's go ahead and create an int variable called Health and set it equal to a 100. Now, I just want you to be aware that both of these are technically correct and will lead to the same result as far as declaring and initializing a variable. Though, I recommend initializing your variables before using them. And as soon as you can, just to avoid any potential errors. And it is just good practice. Now, if you know an integer variable isn't going to go below 0, you might as well make it unsigned. So let's say we were making a game and we know our health friable was never going to be negative. We can make this an unsigned int by putting the letter you in front of the word. And, and now that it is an unsigned integer variable, it will no longer allow us to make this a negative number. So let me go ahead and show you that far to set this to negative 100 out immediately getting air. Basically saying that I cannot set an unsigned int to a negative value next to. Let's go ahead and print both of these variables the console, just to show that they both work on a new line, we'll type console dot write line. And I do recommend new type this out just to get some practice in. And inside our parenthesis, we'll type the variable score. Then we'll do the same thing for our health. Then when we run our program, it should put the value of score being 20 on one line and the value of health being on another. And as you can see when we run our program that does exactly what it does. Then throw out things up. I wanted to show you how we can declare multiple variables of the same type in a single statement and even initialize them if we so chose to. The syntax for this is the data type followed by the name of her first variable, comma, then the name of our second variable, comma, and so on. And you can keep doing this for as long as you want it. Then when you create the name of your last variable, you put a semicolon at the end. So for example, let's say we were making a soccer game. I wanted to make two separate score variables. We could do that like so. We can say n score Team Red, comma, score Team Blue. And then lastly if semicolon at the end. And then if we wanted to initialize any of these variables, we could do so by putting the assignment operator after the name, followed by the value. And you could do that on all of them. None of them are just one or the other. Now in our case, we'd probably want to initialize them both to 0. So let's go ahead and do so. As you can see, our program will run just fine. Now just to show you something, because code is read from top to bottom, we would not be able to put score Team Red and this line of code lattice because it has not yet been declared. So if we did when I print out any of these two variables, we would have to put the code down below. Then I'll go ahead and run a program. And you can see that they were both initialized and print out just fine. Anyways, that does it for this video, we'll be working with ends again here soon when we get into arithmetic. And we'll also be working with them quite often throughout the course. This was just a brief introduction to them and their uses. And the next video we'll be going on for floating point types are numbers with a decimal point. So thanks for watching, and I'll see you in the next one.
10. Chapter 3 (Variables): Floating Points: In this video, we're going to be talking about floating point types. Now before we get started, go ahead and erase all over the code inside of your main method except for a read a key line. This is something we are going to start doing from here on out, unless otherwise stated. Anyways, floating point types are for storing numbers with a decimal point. Though they can store whole numbers, integers are more efficient at doing so. Now, in c-sharp, there are three different floating point types, which I have listed for you here. As you can see, each one has a varying range of numbers that they can store, just totally integer types. They also provide different levels of precision and take up various amounts of memory. Now the flow and the double types serve roughly the same purpose, and you will likely use and see both quite often when working with floating point numbers. The main difference being that doubles take up twice the space and memory as a float. And that they are more precise. That being said on numerous systems, doubles should run better and therefore, I'd recommend using them as your default for floating point type. Now, the decimal type, on the other hand, is mainly used for finances and by scientists and stuff like that, where they need everything to be extremely precise. For most other applications though, they are just slower and take up more memory. Unless you really need the extra precision. I'd go with a float or a double. Next, let's go over how to properly declare and initialize each one. So let's start by creating a new flow variable called Walk speed that holds the value 2.5. So today that will type flow space walk speed equals to 0.5. Then the last thing we have to do as out of suffix based on what floating-point type we're using, which for a float type is enough. So at the end of our value, we simply put an app to indicate that this value, we just typed. This in fact a flow for sluts or compiler. Now the way when I work with a float, not a double or a decimal, a float. Then just put a semicolon at the end. Next we'll create a new line and we'll create a double called run speed and set that equal to 10.2. And just for the hell of that, let's go ahead and declare that and initialize lists one on two different lines. Just to show that we can remember you can do this with any variable type, soil type double space, running speed, semicolon. Then on a new line will say that we want to set R1 speed equal to 10.2. And remember to do that, we just type the name of the variable that we're referring to, followed by an equals sign. And lastly the value. Then the suffix for a double is a d. Though this was not technically necessary as the default floating point type as a double. And lastly, to end our statement, we'll put a semicolon. Lastly, let's go ahead and create a decimal variable called Money and set that equal to 5.004 for school. And so you got And we'll take our data type, followed by the name. Then an equal sign, or the assignment operator, followed by the value, or 5.2004, then decimals or soft. And lastly, a semicolon at the end. Now, another thing I wanted to show you is that let say you are working with a very large number, whether it be an integer or a floating type, there is a way to separate out the numbers to make them more readable. So to demonstrate this, I'm going to go ahead and create a double called bank balance and set it equal to 10 thousand. Then I'm going to go ahead and separate the thousands places from the hundreds with an underscore. There's this creatively called a digit separator when used to separate numbers. This will help them making your numbers easier to read and it will not affect your code in any other way. Then let's go ahead and print all for variables to console on separate lines just to see that they are all working as we expected. Saturday This will take console dot write line, followed by an open parenthesis, our variable name, close parentheses, and a semicolon at the end. And then we'll go ahead and repeat this process for the rest of our variables. And as you can see when we run our program and it prints all four values to console on a separate line. Notice that the underscore from our bank balance variable did not show up in console. So you now know how to declare and initialize the different floating point types. Anyways, that does it for this video, we'll be talking about floating point types more here, sin when we get into operators. And the next video, we're going to talk about Boolean types, which are her storing true or false values. So thanks for watching, and I'll see you on the next one.
11. Chapter 3 (Variables): Booleans: In this video, we're going to talk about Booleans, data type for storing true false values. So for example, let's say that we were creating a game and we wanted to store a variable that would tell us whether or not it was game over. We could create a Boolean or a bool for short colleague game over and then set it equal to false. So let's go ahead and do that by writing. Gameover equals false. And then a semicolon at the end. Then down below, what's there on some texts to roughly similarly gameplay. Suppose say console dot write line. And in quotation marks will print data variable. So say console dot write line, GameOver. Let's print out x i equal to true. And lastly, let's print out our variable again. Now when we run our program, it should print out start pulse. You're a shot. And lastly, trim. And as you can see when we run our program, that does exactly what it does. Now, I'm sure you can think of a million examples of where it'd be useful to know whether or not something was true or false. Like whether a button was pressed, if our character was in the air, and if we were reloading, etc. And you can do all of that by simply creating a bool and then having all sorts of logic to determine what state your bool isn't. Anyways, that is it for this video. And the next one will be going over the char data type, which is used to store a single character. So thanks for watching, and I'll see you on the next one.
12. Chapter 3 (Variables): Chars: In this video, we'll be talking about the char data type. This is used to store a single character. So let's go and create a char variable called the single butter and set it equal to a to D two, this will simply type char when they met single letter, followed by the assignment operator. Then when working with chars, you need a surround the value with single quotation marks. Then we'll put in the letter a, followed by another single HCO and a semicolon at the end. Then we'll go ahead and print out our variable to console using the console dot write line method. And when we run our program, you can see that it prints out the letter. By the way, one thing to know is that when working with chars or strings, which we'll get into in the next video. As your values are case sensitive. So for example, we could change the value of our single letter variable to a capital a. And when we run the program, you can see that it was capitalized. Another thing you should know about chars is that behind the hood, a chart is actually a numerical value as each character has a specific number set and the Unicode alphabet. Now, the useless for chars will become more apparent later on down the line. But for now, I just wanted to make you aware of their existence. Anyways, that is it for this video. And the next one will be going over strings, which has a data type for storing multiple characters. So thanks for watching, and I'll see you in the next one.
13. Chapter 3 (Variables): Strings: In this video, we'll be talking about shrinks. Shrinks are a data type for storing text or a collection of characters or chars. Now, I'm sure you can already think up a 100 reasons why you might want to store some text for using and manipulating in the future. For example, you could use a string distort character dialogue, error messages, someone's name, item names, etc. So let's jump right into how to declare and initialize a string. Now, in the past, we've actually worked with strings every time we've printed text to the console. However, we've never actually stored it anywhere. We've just simply printed it. So let's create a string called name and then go ahead and set it equal to whatever your name is. So today that will type string name equals. And then in quotation marks, you'll type your name. And lastly, we'll put a semicolon at the end. Now, one thing to note is that we could technically store a single character in our string or even no characters and just put the quotes. If we had wanted to, for whatever reason, then let's go ahead and print our string to the console. But this time let's use the console dot write method. We're simply using the console dot write method. Just the show that you can print out variables with this method as well. Anyways, as you can see when you run your program and will print out your name. You've now learned all of the basic predefined data types. In the next video, we'll be going over multiple ways in which to print out variables to the console. So thanks for watching, and I'll see you in the next one.
14. Chapter 3 (Variables): Printing Variables To Console: And in this video, we'll be going over multiple waves to penetrate boast to the console. First, let's create a few variables that describe ourselves. So to start off, let's create a string called name. Then go ahead and set it equal to your name. Then we'll create an int variable called age and go ahead and set that equal to how old you are. And lastly, we will create a double called the hay, and we'll set that we're having. Next. We're going to go over a few ways to print all of at least to console and describe what it is that we're printing. So first we'll type console dot write line. Then in quotation marks, we're going to type a colon and a space, followed by the plus symbol and then the variable name. Then don't forget your close parentheses and a semicolon at the end. Then let's say the same thing for our height. What I'd like you to do is go ahead and run the application to make sure it works. By your name, your age, your next. Let's go ahead and print out the exact same thing in a single statement. But before we do so, let's go ahead and print out a blank lines. To do this, we'll type console dot write line twice, and we won't have anything in-between our parentheses. Now, to print all of this single statement, you have to do is type console dot write line, followed by an open parenthesis. And then a quotation mark will say name. Colon space. Quotation mark, the plus symbol, name. Then we'll do the plus symbol again caused by quotation marks. And inside the quotation marks were gonna tape backslash. And remember that the backslash is a special escape character. And that the lowercase n signifies that we wanna create a new line. Then we'll simply add another plus sign quotation marks, followed by the word age, and so on until we're finished. Then we run our program. And see that we printed the exact same thing twice. Now one thing that I'd like to go over with you, which we're going to start adding to our code in order to make it more readable as a concept called pseudocode. Pseudocode as basically a way of writing your code in plain English. This is something you want to start doing before, during and after writing code to make your code more readable. At-a-glance, though, for example, here at the top, we might write in a comment variables to store our name, age and height. And down here we can say something like print our name, age, and height to console. And down here we can say print to blink lines. In here, we can say that we want to print our name, age, and height in the console again. From here on out, we're going to start writing pseudo-code one viable. So let's go ahead and do that. And another comment line. Let's go ahead and say print blank lines. And then on the next line which create another comment and write and our name and height to consult again. Then just go ahead and copy and paste that. So now that we can easily see what we plan to do with our program, all we have left to do is to write in the code. So below this line here, we'll type console dot write line twice. Then what we're gonna do is we're going to print out our name, age, and height again, except we're gonna be using a process called composite formatting. To do this, you have to do is write console dot, write line, and Len inside of your parentheses, you're gonna wanna put quotation marks, followed by a name and a colon, followed by an open curly bracket. The number 0 and a closed curly bracket. Well, if this number is 0 here is as an index. And you always want to be sure to start at 0. Then after the close curly bracket will simply write backslash n H colon space, open curly bracket to number one and a closed curly bracket then, and we'll just do the same thing. Height. Then after your last close curly bracket, you wanna put in your quotation mark, followed by a comma. And after the comma, you want to write your name variable or the variable that will take up index 0, comma, comma, height, close parenthesis, and then a semicolon at the end. So what this will do is it will automatically insert each variable into the corresponding index run. When you run your program, you should see that you have now printed the same thing three times, but in three different ways. Then it will print another two blank lines. And then the last method I have for you is called the strain interpolation. To do this, all you have to do is write console dot, write line once again. Then setup parentheses way you wanna do, and it's pretty pen your string with the dollar sign symbol. With this does was a teller program that we want to use string interpolation for the following string. Then you want to enter your quotation marks. And inside of those, you're pretty much going to follow the same exact syntax that you've heard about. So we'll say name, colon space, followed by an open curly bracket, except this time, instead of inserting an index, all you have to do is insert the variable name, then a close curly bracket, followed by backslash n, age, and so on. And lastly, don't forget to end with a quotation mark followed by a closed parenthesis and a semicolon at the end. And notice that we didn't put a space before or after our backslash n, as it would have printed to the console. Then when we run our program again, you can see that we have now printed the same thing four times, but in four different ways. Remember that this method here is called string interpolation. But this one here is called composite format. You've now learned multiple ways to print variables to the console and how to print multiple variables using the same statement. In the next video, we'll be talking about constants. So thanks for watching, and I'll see you in the next one.
15. Chapter 3 (Variables): Constants: And in this video we're going to talk about constants. Constants can be numbers, boolean values, strings, or a null reference. Will again No, no oscillator. A consonant is used when you have a value that you don't want to change ever. So for example, you might want to make your max health and again, a constant. Keep in mind that a constant is not technically a variable because it cannot be modified. So let's go ahead and create a constant integer called Max Health and set it equal to a 100. And all we have to do is use the const keyword before our variable. The credit or max held constant. Const. And Max house equals a 100. And as you can see, if we were to try and change our max, how we would get in there. Because like I said, constant cannot change. Then let's go ahead and print max health the console, just to see that it worked. And as you can see when we run our program had done. And in the next video, we'll be going over collecting chars and strings from user input. So thanks for watching, and I'll see you in the next one.
16. Chapter 4 (User Input): ReadLine & ReadKey Methods: In this video, we'll be talking about getting user input using the console dot read line method and the console dot read CKY method. Now, what the readline method does essentially is record a string from the time it is called until the user hits Enter or Return. Then one to those done recording the string, it returns the string value and the read method obtains the next character or function key pressed by the user. But before we begin, we're going to start off by writing some pseudocode. So first we're going to ask the user for a name. Then we're gonna save the name as a string. And lastly, we're going to print the name. And the top part here. Let's start by saying console dot, write line, then water for their name. So I'll say What is your name? Colon space. Then we need to save the user's reply and a string. To do this, we're going to use the console dot read line method. So, and we'll say console with a capital C, just like above. Then we're gonna say diarrhea line with a capital R. And don't forget your open and close parentheses and a semicolon at the end. And like I said, this line here is going to record a string from the time it is called until the user hits enter or return. But we still need to store the string value inside of a variable. Otherwise we'll leave it. So write buffer method, we're gonna create a new string and set it equal to whatever this method here returns, which is going to be a string as well. So we'll say string. Let's just call this name and set it equal to this method. And lastly, we need to print the name back to the user. So once again, we're going to say console dot write line. And quotation marks will say your name is colon space. Then we'll just add on their name using the plus sign. Like so. Then let's go ahead and run our program. So as you can see, it asks for a name, can type whatever you want, and hit Enter. Then it's going to print that back to us on a new line. The reason it is on a new line as because we've had a hit enter or return at the end. Then I just want to show you that something else will work as well. And that is that we can change this top line here to console dot write instead of console dot write line. And this will work just fine as well. The only difference being is that world type her name on the same exact line as less. And you can see how that plays out if we run our program here. So it says what is your name? We type it out on the same exact line. Via Enter and it prints it out for us down below. And lastly, let's quickly go over how we can do something similar. Except this time we'll be storing a char value using the console.log method. And to keep things simple, we'll just leave everything the same. I just want to show you how this is done. So instead of saving the name as a string, we're going to save it as a char value. Then we're going to say console dot read key with a capital K instead of console dot read line. And notice how we got an error. And this says that we cannot implicitly confer from type System.out console key info to HR. Now, don't worry about this too much right now, as we'll be going over how to explicitly convert values later on in this course. For right now, I'm just going to show you another way that we can get a char value using this console dot read CKY method. And we're going to do this by accessing a property within the method. And we'll be going over properties later on as well. For right now, just follow along with means. So you can see the syntax that we are using to access the property that we need in order to get the right data type for HR using this method. So right after our console dot read key method here, make sure this is before the semicolon. We're gonna be using the member access operator or the period symbol. So will say dy. And then we're just gonna say key char with a capital K and C. Like I said, this here is just a property inside this method that holds the proper value we need for HR. Just like we access this read method inside of the conflict class using the member access operator. We were able to do the same thing with this key char property inside of our read CKY method using the member access operator as well. So let's go ahead and run our program. Right now. It's gonna ask for our name. Then as soon as we type one letter. And so I'm actually going to print that back to us. And that's because console.log key only obtains the next character type. And because we don't have to enter or return, it didn't print that on a new line. So if we wanted to clean this up a bit, so we could say console dot write line below here, create a new line when our program again. And as you can see, it now works a lot better. And obviously if we wanted to clean this up a bit, we can say what is the first letter of your name? And say the first letter of her name is, et cetera. So you now know how to get user input as a string and as a char value using either the console dot read line method or the console dot read method. And just remember when storing a char value using the console direct key method. You'll also need to access this char property. Or you could explicitly convert the value from this to a char. And we'll be going over how to do explicit conversions a little bit later on in this course. Anyways, that does it for this video. And the next video, we'll be collecting userInput again, except this time, we'll be getting a number instead of a string value. So thanks for watching, and I'll see you on the next one.
17. Chapter 4 (User Input): Convert.To Method: In this video, we're going to be going over a way to collect a numbers through user input will be doing this using the convert to method. So essentially what we're going to want to do is we're going to want to ask for a number. Then we're going to want to save that number. And lastly, Well one and print it out. So an example of what we might ask her as someone's age. So we can say console direct line, vendor start things off, will have to collect the string that they just type them. String. We'll call it numbered type. And we'll set it equal to console dot read line. Then we're going to use the convert TO method to turn whatever they typed in into an integer value. So we'll say int number, say convert with a capital C dot two with a capital T And with a capital I, the number 32, and then open parentheses. And inside of here we're going to enter our string. So say number types. Then we'll end our statement with a close parentheses and the semicolon. Now, just to clarify things were not technically using that convert to method. Where we're actually doing is accessing a class called convert that has multiple methods for converting from one data type to another. And because these methods start with a word too, for example, here we're using the two N32 method. I'm simply going to refer to it as the convert to method for simplicity. So just keep in mind that when I say that convert to method, I'm simply referring to a method of doing things, not the actual name of the method itself. And lastly, we will just want to print out the number to show that it worked. So you might say something like you are space on our number. They'll add an another Schengen, say, space years old. And then make sure you don't forget the plus symbols in between your different data types. Real quick, let's just go for code here from top to bottom. So first, we are asking the user to type in a number being that age. Then we have a string called number type, which is going to store the value that our console dot read line method returns, which is of the type string. Then I'm recruiting an nth column number that is going to store the integer value. That list method here returns or convert to a method, takes the string being number of tape and attempts to turn it into an integer value. Once that is done, it will return that integer value. And then we are storing it int number. Then we are printing out you are the number the user typed in, years old. Then we'll just run our program to make sure it works. Now this was only going to work if you type in an integer value and make sure there's no space, those are commas or anything like that. So it's going to ask how old we are. We'll type in a number, hit Enter, and then I will print out you are your age, years old, by the way, but you could use those convert to method to convert it to all sorts of different variable types. So for example, we could turn this into a double by saying convert to a double or a float by saying can route to single, and many others. When you're originally typing the method after you type in the word to, you can scroll down in this little drop-down menu and see all the different types that they have available. Keep in mind that if we were to change this type here, we would also have to change the type that we're storing in as well. Anyways, let's look for this video and the next video we are going to be doing the exact same thing, except we're going to be using the parse method and settled a convert to method. And we'll also talk about the differences. So what I'd like for you to do is save what we have here and we'll use it in the next video. Anyways, thanks for watching, and I'll see you in the next one.
18. Chapter 4 (User Input): Parse Method: In this video, we'll be collecting a number value from the user. Except this time we'll be using the parse method instead of the Convert to method. First things first, let's go ahead and just copy and paste all of this code we have up top here. Next, let's highlight our original code and comment it out. Remember you can do that by hitting this button here at the top. Then the only thing that we have to do differently here is change this method. So what we're going to change this to is 32 dot parse open parenthesis. Then we'll insert our string once again, followed by a closed parentheses and a semicolon at the end. Now where I'm getting this N32 from, as from this here. So if you mouse over your integer variable, you can see that it so System.out.print 32. And it represents a 32-bit signed integer, which is where this N32 comes from originally. Now if I were to change this to a float type, you can see that so System.out single and therefore, you just have to change this to single. Anyways, I'm gonna go ahead and undo that and run our program. As you can see, just like it did with it can hurt to method and asked how old we are. Once again, you'll need to insert a valid number and make sure there's no spaces are commas. Otherwise you will get an error and then hit Enter. It prints out our edge and said the string here. Now the difference between our parse method and our Convert to method, as that first string was equal to null, which we'll get into later on. Basically if our string was equal to null, it would essentially be the same as saying that our string wasn't referring to anything. And the difference being, is that if our number typed variable was equal to null or convert to method would return the number 0, whereas our parse method would return an error. So the main way to decide on what method to use is to determine what you would like to happen if the string were to be equal to null. Now I don't fully expect you to understand that now, let's, let's just something to keep in mind for the future. There is a method for determining whether or not your string is equal to null before using your parse method. The method for doing so is called the parse method. We will go over this method a little later on when we learn if statements. Anyways, that's it for this video. And the next video, we'll be going over some basic arithmetic in programming being addition, subtraction, multiplication, and division. So thanks for watching and I'll see you in the next one.
19. Chapter 5 (Operators): Basic Arithmetic: In this video, we'll be going over some basic arithmetic operators, being multiplication, division, addition, and subtraction. I have them all listed here at the top, followed by their symbols. So first thing we're gonna do is write some pseudocode. So we'll want to create two number of variables. Then we'll want to create a result variable. Then we want to do some math. And lastly, we're going to print out theories all. Let's create two integer variables. Will just come number one, number two, number equal to ten. And let's take a number equal to five. I don't just create an int and initialize it to 0. And go ahead and clean this up. Now at the bottom, let's just go ahead and go to console dot write line statement inside of our parentheses, we'll just insert the variable result. Then all we have to do and articulate the result of these two numbers being multiplied, divided, added, or subtracted together. And say result equals number one plus number two. And then a semicolon at the end. And then all we would have to do is change the symbol according to what we want to detail. So now if we run our program, we can see that it prints out 15. Now let's say I wanted to add five to number two here. But I would have to do is say number two. Number two again, Hive. And then let's go ahead and change where we're printing out here at the end to number two. And the reason we have to do that is because our assignment operator is going to take the result of everything on the right and assign it to a variable on the left. So basically, just now says that we wanna take five plus five, which is ten. So when we run our program, you can see that it will now print out ten. How do we forgotten to re-enter a variable name here? It just would have set number two equal to five. And just remember you can change this operator to whatever you wanted to be. Another thing you can do as a sign-up variable directly equal to another. And say number one, number two. Then if we remove this line above, number one would now be set equal to five. Then if we change the sign here and run our program, you can see that it prints out class. Anyways, let's go ahead and change this back tourism. And then in this line here, let's say result equals. And then one thing I wanted to know is that you can have as much math on the site as you weren't an l work just the same way it did as when you were taking math in school. So your president is going to be multiplication, division, addition, and subtraction. Anything in parentheses will happen first. So if we were to say in parentheses, one, flash number two, and then multiply this by five and put a semicolon at the end. We would now get the result of 15 times five. When we run our program. We can see that that's what happens. Anyways, I'd like her, I love you to go ahead and save the code that you have here, cuz we're gonna use it in the next video. And the next video we'll be going over the increment and decrement operators. So thanks for watching. I'll see you on the next one.
20. Chapter 5 (Operators): Increment & Decrement: In this video, we are going to be going over the increment and decrement operators, which are as follows. So your increment operator is two plus symbols and your decrement operator as two minus equals. What this is is basically an easier way of adding one or subtracting one from a variable. They made this possible just because of how often people add and subtract one from variables will be using these a lot, especially when we get into loops and going through collections. So for example, let's say we wanted to add one to our number one variable. All we would have to do is say number one and put a semicolon at the end. And now are number one is equal to 11. So this is the exact same as the method we used in the last video where we said, number one, number one plus1. Anyways, I go ahead and comment that I'll send down here and let's go ahead and change for us all to number one, just to show that it worked. And it will go ahead and run our program. And as you can see, it printed out 11. And if we were to change this to minus, minus or the decrement operator, you can see that it would print out nine. Ok. Now another thing I want to show you is that this operator can be used in different ways. And what I mean by that is this. So let's go ahead and delete this line of code. And we'll say result equals number one plus, plus and i semicolon. And then we're going to basically recreate this line except with a slave. So were gonna say result equals plus, plus, then number one. And then after each of these lines, what's go ahead and print out the result. I'm going to also comment out this line down here at the bottom. And then inside that both of these, let's just go ahead and add some text to make it more obvious which operation we did. So in here we'll add a string and we'll say number plus, plus colon space. We'll put in our quotation marks, and don't forget to add a plus symbol in between your string and your variable. And then we're gonna go ahead and do the same thing for down here. Then in between both of these, let's go ahead and set result back equal to 0. Now, the difference between these two lines as this. So I'm just gonna go ahead and add a comma here. Basically this one here at the top is going to set result equal to number one. Then it's going to add one to number one. While the bottom one here is going to add one to number one. Then it's going to cite result equal to number one. I'll so we're going to add one more line of code here after a result equals 0 and say number one equals ten. This way we have the completely fresh start between these two sections of code. So just sign here, and this one here will both add one to our number one variable. However, result is going to be different. And as because like I said, this one is going to first set result equal to number one, and then it's going to do the addition later. This is signified by the fact that our increment operator is after the variable. Well, this one is gonna do the addition first, and then it's gonna set result equal to the result of that. And once again, let us signify it by the increment operator being before it, the variable sum math first done the assignment, whereas this one was the assignment first than the map. So what's going to happen when we run our program, as a result is going to be set equal to ten. And then number one is going to equal 11. Then on our first line and will be printing out ten. Then we're going to set result back equal to 0 and number one back equal to ten. And then on a separate line, and it's going to print out the value 11. And as you can see when we run our program, that's what happens. That our number one variable was in fact incremented. Let's go ahead and print out number one after each of these as well. So I'll say console dot write line number one. And we'll just copy and paste that down below. As you can see, it printed 11 twice. Anyways, let's up for this video and the next video we're gonna go over them modulus operator. So thanks for watching, and I'll see you on the next one.
21. Chapter 5 (Operators): Modulus: In this video, we'll be going over the modulus operator, which as you can see is this lip percentage sign as the symbol. And what this does is return the remainder of dividing two numbers. So let's go ahead and start off with some pseudocode. First we're going to create two double variables. Latin woman, I create a result variable. W1 will wanna do some math. And lastly, we want to print out our result. So we'll start off by creating two doubles call number one and number two. Equal to 0 will create a double result variable. And then down here at the bottom, let's go ahead and print out our result. Then let's go ahead and number one. And lastly we'll say result equals number one, modulus number two, and a semicolon at the end. What this was going to do is take a number one being divided by number two being five. And then it's going to excite result equal to the remainder. If there is no remainder, result would equal 0. Then when we run our program, because six divided by five has a remainder of fun. That is what it's going to print out on a separate line. One way to find out if a number is odd or even is by using the modulus operator. So for example, if we wanted to know if number one was odd or even, we can say number one modulus and then two. And now if we had a remainder, we would know it was odd and if we didn't, we would know as even. Anyways, that's it for this video. And the next video we'll be going over assignment operators. So thanks for watching, and I'll see you in the next one.
22. Chapter 5 (Operators): Assignment: In this video, we'll be going over assignment operators. First, let us go ahead and create an integer. Call it number. And we'll go ahead and set that equal to tn. Now before if we wanted to do any kind of operation to our number variable, we would either use the increment or decrement operators, or we'd say some length is number equals number five, for example. Now the assignment operators basically make this operation much easier. So if we wanted to create this exact operation about, oh, we'd have to do essay number plus. And these two lines of code are exactly the same. So just to prove less, let's go ahead and in-between these lines, let's say number equals ten. Just send it back to the original value. And then below each one of these, let's go ahead and print out number. And then when we run our program, you'll see that it prints out twice. And one thing to know is that you could change this operator here to be any of the operators we've gone over in thus far. Anyways, let us up for this video. And the next video we're gonna talk about concatenation. So thanks for watching, and I'll see you in the next one.
23. Chapter 5 (Operators): Concatenation: In this video, we're gonna talk about concatenation, which is a way of combining multiple strings together. So first off, let's create a string variable. And we'll just call it string one. Then set it equal to Hello space, then will create another string called shrink to equal world. And lastly, and we'll create another string called combined shrinks. And we'll set x1 equal to a blank string. Now to concatenate string one, and we'll say combine shrink equals string one, shrinks. Then we'll go ahead and print out combining shrinks. And as you can see, that the two together and print to the console. We could even add a string n here without it being a veritable. So for example, we could, I'm an exclamation point. And if we run our program again, you can see that it has now added. We could've also used the addition assignment operator like so. We could have such string one, string tail, and then printed out string1. And as you can see that the exact same thing. And the next video we're gonna be talking about casting. So thanks for watching and I'll see you in the next one.
24. Chapter 5 (Operators): Casting: In this video, we're gonna talk about casting. So first let's start by creating two integer variables. And we'll say int num one equals five. And we'll say num two equals four. Then let's go ahead and create a flow called Herzl and set it equal to numb one plus num to us right now what we're doing is setting our float called result equal to the value of number one and number two, both being integers being added together. So in this operation we are converting an integer data type to a flow. Casting is when you turn one data type into another. And the reason this is okay, is because of float can hold an integer value with more precision. However, you can not do this the other way around. So because our float can hold any value that our integer Ken and more, it will implicitly casted over. So if we print out the result and run our programs, you can see that it'll print out nine. However, this wouldn't work the other way around. So if we were to, for example, change those to a byte, you can see that when we run our program, we get an error. And as you can see, this arrow says that you can not implicitly convert type ent to type by an explicit conversion exist. Are you missing I cast. Now anytime you're converting over to a type where you'll potentially lose information, you need to explicitly cast it. So what we have to do as explicitly turn the result of this operation into a bite. To do that, all we have to do as n parentheses, put the data type that we want. So in this case we put by it. And then because we are working with this whole operation, we need to also put this inside the parentheses. And now when we run our program and I'll print out nine. Keep in mind that the datatype byte can hold the value nine normally. However, because it holds less than the data type and it will not implicitly converted. Now these parentheses here, we're only necessary because we were working with an operation. How do you done something like this? Like say result equals num one. And then explicitly casted this tool. We would not have needed the extra set of parenthesis. So if I go ahead and comment out this line above and run our program, you can say that result was equal to numb one. Anyways, go ahead and save what you have because we are going to use it in the next video. And in the next video we're gonna talk about truncating. So thanks for watching, and I'll see you in the next one.
25. Chapter 5 (Operators): Truncating: In this video, we're gonna talk about truncating, which means to cut off the end or something. So to show you an example of this, let's go ahead and erase. So Sina code. Then much change num to overflow. And we'll set it equal to 4.5. And then don't hurry or F at the end. And lastly we'll say int result equals n1 plus n2. Then we'll explicitly cast this operation to an end. Now because an integer cannot hold the floating number, instead of this being equal to 9.5. That's just going to equal nine that us because it truncates everything after the decimal point. It does not round up or down, it just gets rid of it. And as you can see, when we run our program and print out the result, and it will simply print nine. Even if we were to change this to 4.9, we would still get the same answer. In the next video, we'll be talking about scope. Anyways, that's it for this video. So thanks for watching and I'll see you in the next one.
26. Chapter 6 (Conditionals): Scope: In this video, we are going to be talking about variable scope. So I have some notes here and in this episode you guys don't have to type anything. I just kinda wanna go over some stuff with you. So first off, variables must be made within a class. Thus far, we've been making all of our variables within our class program, which begins here at this open curly bracket, and then here at this close to him. And as you can see, Visual Studio add-in unless dotted line to show us that these two curly brackets are associated with one another. Next, there are three different levels of variable scope. You have class or object, method or function, and then block, leap or statement. These are just different names for the same thing. So class and object are the exact same thing and the name has just used interchangeably. Same goes for these ones as well. So if you were to declare a variable right here within our class, and it is now available anywhere below within the class. Now, variables declared within the class are called fields or a class members. And like I said, they can be accessed anywhere within after declaration. They can also be accessed outside of a class by using access modifiers, which we'll get into later. There are also available to any non-static method or function. Note that our main method as a static method, and we'll get into static and non-static later on. Next, if we were to declare a variable within a method, it would be available anywhere within the method after declaration. So it'd be available from this point onward until this closed curly bracket, which signifies the end of our method. These variables are normally called local variables. And like I said, they're accessible anywhere within the method after declaration. Also, Method variables cannot be declared twice, meaning you cannot have two with the same name. Now, the same does apply for class variables as well. However, you can have a class variable and a method variable. How does the exact same name? But within their individual scopes, they can not have the same name. Which is why you've seen me comment out certain lines of code that we've copied, because you can't declare two variables with the same exact name within a method. And they, you can't have two class variables with the same name. A class variable could share a variable name with one of its methods. Method variables also no longer exist as soon as the method is done executing. Meaning once we hit this close bracket here, any variables declared within the method no longer exist. Lastly, we'll go over variables declared at the or block level. We'll be going over loops and shortly. However, I just wanted to give you some insight as to how variables declared within a loop work. So once a variable is declared within a loop and it is now available anywhere below, these are normally called Looper statement variables and are only accessible anywhere within the loop. Meaning as soon as we hit this close bracket here, any variable we declared inside would no longer exist. Anyways, that's it for this video. And the next video we'll be going over exactly what conditional statements are. So thanks for watching and I'll see you in the next one.
27. Chapter 6 (Conditionals): Intro To Conditional Statements: Unless video we're gonna be talking about conditional statements. A conditional statement is a statement that checks per a certain condition and then flight condition that it will run a specified section of code. So just to give you an example of how this works, you'd have the condition and then normally some block of code. So as our main method was being executed, as soon as I came across this condition, it would check to see if it was true, if the condition was true, and it would run all over the code inside. However, if the condition was false, all this code would be skipped entirely and it would continue on down here. Anyways, this was just the basics of how a conditional statement works. So things you might want to do is check if a button is pressed. If a number equals a certain amount, if a string, so something specific, NFL player characters reloading if a certain event has taken place, make cetera. Anyways, that is it for this video. And the next video, we'll be talking about relational Andy, equality operators, which are used in a condition to check for various things. Anyways, thanks for watching and I'll see you in the next one.
28. Chapter 6 (Conditionals): Relational & Equality Operators: In this video, we'll be talking about relational and equality operators, which helped you to check for a certain conditions. So first off, we have the equality operator, which checks if t values of two operands are equal or not. If they are equal, that condition will become trail. The equality operator is two equal signs. So for example, if I had the number ten on both sides of the equality operator, the condition would be true. Next, we have an operator that's checks if two things are not equal to one another. This operator as an exclamation point and then an equal sign. So once again, for example, if we had the value ten on both sides. This is because in order for this condition to be true, these two things need to be. In another. Next, we have some more basic operators that you've probably seen before. And you have a greater than, which is just the greater than symbol. Less than, greater than or equal to. And then we have the less than or equal to. So in order for this one to be true, the value of the operand on the left has to be greater than the one on the right. The opposite can be said for the less than and what's the value of the operand on the left has to be less than the value of the operand on the right than the greater than or equal to. Check if the value of the operand on the left is either greater than or equal the value of the operand on the right, then it is the exact opposite for the less than or equal to. Write checks to see if the value of the operand on the left is less than or equal to the value of the operand and the right anyways, but does that for this. And the next video we're gonna talk about logical operators. So thanks for watching, and I'll see you in the next one.
29. Chapter 6 (Conditionals): Logical Operators: In this video, we're gonna be talking about some logical operators which helped you to check if certain conditions are true. So when working with conditional statements, you're gonna have something like this. In which the purpose of is to find out whether this condition is true or not. So it knows whether or not to run a specific section of code. The first logical operator we're gonna go over is the operator which checks to see if both operands are true. The operator for this as symbols. So for example, we could say if a is true and if b, then we want it to run a certain section of code. Next we have the or operator, which is two vertical lines. So for example, we can say if a or B is true, then we want to run a certain block. Okay? And lastly, we have the not operator, which he kinda saw in the last video, which checks to see if a condition is not true. The operator for this as an exclamation point and go for the condition. So it looks something like this. So if we had a bool called a and it was false, this condition would now be true because we wanted to check if that was not true. So if condition a were false, then we run this block of code because now are not true condition would be true. Anyways, that does it for this video. And the next video, we're gonna be going over f statements, which was our first conditional statement, which checks to see if a condition is true and then runs homeland block of code. Anyways, thanks for watching and I'll see you in the next one.
30. Chapter 6 (Conditionals): If Statements: Unless video we're going to be talking about if statements. The syntax for this is as follows. We would say if parentheses, and inside those parentheses would be our condition. And afterwards we wouldn't have that block of code that we run a run if her condition was met. So let's go ahead and try this out. First will create an integer variable called number and x i equal to ten. Then we'll say open parentheses. Number is equal. Remember the operator for that as T0 equals signs to ten. Then we want to run the following block of code. And then here we'll say console dot write line. And then inside of quotation marks will say condition was true. Now when we run our code and it should print out condition was true. And as you can see that that's exactly what it did. However, if we were to change our variable number to five, for example, it will now print out nothing. And this is because this condition would no longer have been met and therefore, this block of code would have been skipped entirely. Now you can see when we run our code and print out nothing. Now just to show you something that you can do for readability if you only have a single line of code that you want to run inside of an if statement. The curly brackets are technically unnecessary and your code can just look like those. Some people find this to be more readable. Feel free to use whichever you prefer. Also, we can swap this operator out with whatever we wanted. So we could say If number is greater than or equal to ten, for example. And now if we set this to ten, our code would run. If your condition was met. Once this block of code is done executing, and it will continue running code from here on out. So for example, if I were to say console dot write lines, end up if statement. You can see that that would be printed outright nothing. Anyway as I'm gonna go ahead and erase that. And I'd like for you to save the code that we have here because we're going to use it in the next video. And the next video, we're gonna be talking about nesting if statements. So thanks for watching and I'll see you in the next one.
31. Chapter 6 (Conditionals): Nesting If Statements: In this video, we're gonna be talking about nesting and if statements. The nested IF statement as an If statement inside of another if statement. To test this out, let's change the name of our number variable to number one. Now, one way to do this in Visual Studio would obviously be the genes, the name here and here. However, one thing Visual Studio allows you to do is to highlight the name, right-click on it. And then I have renamed. And now when we edit the name, it'll edit all instances out those names variable. So you can say number one. And as you can see, a change both of them and then just had applied. Then we'll create another variable called number ten. Well, I'll set this one equal to five. And our if statement condition, let's just say if number one is equal to ten, and then etc. Console dot write line. Let's have the word first before either the word condition. Then right below that, let's go ahead and create a new if statement and check if number two as equal to HIV. And we'll say console dot write line. And we'll say second condition was true. So now if number one is equal to ten, then this block of code will run. If this condition is false, then I will skip all the way to the end down here and continue reading code, meaning in which kept everything in here entirely, including this f statement. However, if this condition is true, so if number one is equal to ten, then it's going to run this line of code pressure. And then it's going to check if this condition is true. To determine whether or not I should run this block of code. If this condition were false, it's kept till the end of this and continue on to the next line. If it were true, then I'm going to read all of this code and then continue on. So if we were to run a program now, we can see that it would have print out both of these lines. If we were to put the not symbol before our second condition, and then put this whole thing inside the parentheses to avoid getting an error. Now, I would want to know if number two not equal to five because it wouldn't want those condition did not be true. So if we were to run our program now, only the first condition would have been that also you guys can have a much longer operation on this. So I could say if number one was equal to ten or if number one plus phi, for example, was equal to 20. Then let's go ahead and change number two to six. So now if we were to run our code, both of these would print out. However, if we were to change our number one variable to something like 13 and run our code only the second conditional would be true. However, it would not run because those conditions that would have been false. So therefore we would print out nothing. But if we were to change this to 15, when this condition ran, it would check to see if it was equal to ten, which it is not. But because we have the or operator here, but also check to see if this condition was true. And as long as one of these is true, our program would run. Now, I would take number one being 15 plus five, which is 20, and then see if 20 is equal to 20. And because of this condition would be true and thus would run as well. Because number two is not equal to five. And you could keep this going for as long as you wanted. You could even thrown an and operator and have another section of code similar to this one. And then just simply put these in parenthesis. Now, obviously in this case this machos, but if these were different era now check to make sure either one of these two is true because we have the source symbol here. And at least one of these would have to be true. Anyway is I'm gonna go ahead and undo that. Basically, you want to use f statements anytime you want to check if the condition is true. And then effort as you want to run a certain section of code. Anyways, that is it for this video. And the next video we'll be talking about if else statements. So thanks for watching and I'll see you in the next one.
32. Chapter 6 (Conditionals): If-Else Statements: In this video, we're going to talk about statements. So how they work as, as follows. Condition. Then you'd have a block of code that would run m psi conditional is true. Afterwards, you would say else. And then having another block of code to run EFSA condition was false. So for example, we could say any number higher than, let's say number is equal to five. We want to print out number is equal to five. Then we can say print out number was not equal to one. And then the lower if-else statement, let's print out and of f statement. So right now, if we were to run a program that would check if number is equal to five. Because let us trail, it's going to go ahead and run this code here. Now our else statement only runs if the if statement was false. So because in this case it would not be SAS code here would be skipped entirely, and then the rest of the code would be executed. So if we run a program and it's gonna say number is equal to HIV and the above statement. Now, if we were to change this to, let's say two, and run our program again. You can see that this block of code did not run. However, this one did. Because an else statement basically says, otherwise, I want to do this. The reason this is useful as because obviously in our case, if number was equal to five or if this condition was true, we would not also want to print out the number was not equal to five because that wouldn't make any sense. Also, one last thing I wanted to show you is the inside of an if statement. You can say if and then you can just type in false high in. So we can say f true. Run this block of code. Now, obviously this is always going to be true, and therefore this one always print. And we can also do the same by saying false. And now this code, and here, whenever, right? I just wanted to show you that this was possible. However, I doubt you will ever meet it. Anyways, that is up for this video. And the next video we're going to be talking about Else statements. So thanks for watching, and I'll see you in the next one.
33. Chapter 6 (Conditionals): Else-If Statements: In this video, we're gonna be talking about and if statements, which basically work as follows, where you'd say if a condition is true, run this block of code. Then we would say else. Another condition was true. We want to run this block of code. However, listen only runs if no previous condition work true. And lastly, you can put in an optional statement at the end, which only runs a block of code if none of the previous conditions were true. Making it a catchall. So for example, let's say count equals 30. Then we'll say Emma count is equal to 30. And we want to print out as last trend five. And we want to print out low. We can either here or we can even put another else. And we'll say if m is equal to 0, then we'll print out empty. And then like I said, you can have a catch-all statement here at the end, being an else statement to run anything in this block of code if all of these are false. Anyways, I'm gonna go ahead and remove them. Now at the bottom here, I'm going to print out and Novo statement. So how this else-if statement works, and let's see if ammo count is equal to 30. If it is, it is going to run this block of code and then it's going to skip to the end of her else-if statement and continue running. However, if this condition is false, then it's going to check if ammo count was less than five. If it is, it would run this block of code and then skip to the end. However, if this condition was false, then I would check this block of code. And if that were true, it would run the code within this block. Or if that was false, then I would run this. Just note that as soon as one as true, and it's only going to run that block of code amongst skip to the end. So if we were to run our code now, it's gonna see if AMA countless equal to 30. And right now ammo count is 30. So because 30 is equal to 30, so this condition will be true. And we're going to print out full. Then because our else statement here only checks for one condition to be true and we'll skip to the end and print out a statement. So let's go ahead and check that. Now as you can see, that's what happened. Now, what if we were to change this to something like 20? If we were to run our code all over, these would be false. And that's because our ammo count will not be equal to 30. It would not be less than five into it not be equal to 0. So all it's gonna do is print out endo statement. Now, if we wanted to catch something like time, we could add an another else-if statement and check if ammo count was greater than or equal to five to catch everything else. Or we could just simply create an else statement. And inside of here, we could print out none torture. Obviously, this isn't a great example of excuses, but I just wanted to show you that it's basically a catch-all. And now this will only run if all of these were false. Because we're basically saying if this condition a shoe run this, run this, etcetera, and then saying otherwise run length k. So if you ran and now I'm going to say none or true, and eventually anyway, so that's it for this video. In the next video, we're gonna be talking about switch statements. So thanks for watching, and I'll see you in the next one.
34. Chapter 6 (Conditionals): Switch Statements: In this video, we're going to be talking about switch statements. Now, there's a couple of differentials between also statements into a switch. So if you have more than three else condition checks and an else-if statement, and you are only checking for a specific value, then you'll want to use a switch. The syntax is as follows. The switch and then parentheses. You want an expression, then an open curly bracket. And then inside you wanna say case, run code. And then at the end of your section of code, you want to say break semicolon being can do this as many times as you'd like. Case phi u, one, run code break, case by U2, U3, etcetera. And then you'll have a closed curly bracket at the end. Now, optionally, you can enter a catch-all, which would have basically serve the same purpose as our else statement did and our MFLs and our else-if statements, we would say default colon, run code. Right? Okay, so let's go ahead and try this out. Let's create an income number and set it equal to five. Then we'll say switch. And inside parentheses will insert a number variable. And I'll go open and close curly bracket. And inside, let's say case one, colon, console dot write line. And let's just go ahead and insert our variable in here. And then we'll say break. Now if you want, you can answer all over this inside of open and close curly brackets like so. However the associate necessary. But you can do whatever is more readable for you. And then I'm gonna go ahead and create these. Then lastly, go had a default which remember is optional. Colon, console dot, write, line. And then I'm going to go ahead and print out none were true. And lastly, outside of this switch, switch. So remember you want to use a switch statement anytime you have three MR. elsif conditions, the check and an else-if statement, and you only need to check for a specific value. The reason I say that as you can not put any logic in here, so I cannot say case less than four, for example. Now when we run our program, that's going to go ahead and it's going to check number, and it's going to say f, it is equal to one. I want to run this. Otherwise it's going to check if it's equal to two and so on until it gets to here. And then it's going to go ahead and print that number being fine. Otherwise, if none of these were true, thus here would be printed out. Then it's also going to print out and dosage. I printed out five inside the endoscope. And example of why we might wanna do this is let's say we had a bunch of different dialogue options and the game. We could ask a question and then have multiple options, each equal to a different value. And we can say if option one was pegged, say this, or run this animation case to do this one. Thanks Sandra. Anyways, that's it for this video. And the next video we're gonna talk about the ternary slash conditional operator. So thanks for watching and I'll see you in the next one.
35. Chapter 6 (Conditionals): Ternary Operator: In this video, we'll be talking about the ternary or conditional operator, which the syntax for those homes. We basically wanna say condition, question mark, colon value if false. And then set this equal to something. So for example, let's create an end number equal to four. Then we'll create a bool called Less than five. Afterwards, we're gonna wanna say less than five. I'll say number less than five. Question mark, true, colon false. So now less than five is going to be set equal to trail. If this condition is true, or I'll be set equal to false. And with this condition is false. Now, this doesn't only work for a bulls to show those, let's create another integer called number two. Then let's say number two. Number less than question mark, colon. And then let's go ahead and print out less than five. And on a new line. Let's also print out number two. So I run a program, what's going to happen as our bull less than five is going to be equal to true or false. Depending on whether this condition is true or false, then our number two variable is going to be equal to 50 or a 100, depending on whether or not number is less than five. So it's going to happen when we run our program has less than five psi equal to true. And number two, there's going to be set equal to 50. So I run our program, we're going to be printing out true and then 50 on two separate lines. And let's go ahead and change our number five here TO three. So now when we run our program, that's going to say true and then 100. So basically you're saying, I want you to check this condition. Then based on whether it's true or false, I want you to set whatever's over here on the left there were assignment operator equal to one of these items. Anyways, that does it for this video. And the next video, we're gonna be going over the try parse method, which I said we'd be going over once we had learned if statements. Anyways, thanks for watching and I'll see you in the next one.
36. Chapter 6 (Conditionals): TryParse Method: In this video, we're gonna be going over the parse method. Most of the time when working with conditional statements, you're going to want to get some kind of user input. Personally, we're kinda wanna do is create a number variable. Then Bergen, I wanna get some user input. Then we'll set number equal to the input. So we're going to say int number. Let's just go ahead and set this equal to 0 for now. Then, let's say console dot write line type number. Then let's create a string called user input and SQL to console dot read line. Next we're going to say int tri-party. And then inside of parentheses we're going to insert our string being userInput comma out number. I'm going to semicolon at the end. Then down here, we're gonna say a number equals in dot parse userInput. Now, this isn't technically necessary because our tripe parse method is going to automatically parse user input into number if it returns true. However, we're gonna leave this here for some future examples in this video. However, we only wanna do this if this method up here was equal to true. So we're gonna say f worked. And because it, let's us live bool. This was just going to check if work is currently equal to true or false, which is going to depend on whether or not it was able to come in where our string user input into an integer and put it into number. So we're gonna say f worked is true. Then we want to go ahead and change number equal to n dot parse userInput. And lastly in southern risk statement, let's go ahead and print out numbers. So now when we run our program, it's gonna ask us for a number and a higher to insert 20, let's say and hit Enter. It's gonna go ahead and print out 20. Now we had done something similar to this in the past by just using our parse method, have R. By using the try parse method, we can now make sure that we're without causing any errors. Show to show you what I mean. Let's go ahead and comment that out and also comment how our if statement. Now when we run our program, if I were to insert something like 5x plus four and hit enter, how would immediately get an error? Because our input was not in the correct format. For same thing would happen if I were to try and insert letters. However, if I go ahead and uncomment, those are try parse method. And it's going to make sure that our input can in fact be converted into an integer and inserted into our number variable and f. So this will return a boolean value being true. If it did not work, it will return false. And it would still change the value of number. But because the conversion didn't work and it returned false, it is simply going to change it to 0. So if for whatever reason are try parse method returns, false. Number will be set equal to 0. If it returns true, then it's going to be set equal to whatever we typed in prey user input and takes us from the top. So for us we created an insert call number and set that equal to 0. Then we ask the user to type a number and then save that with a typed into a string called user input. And user input was saving any input tight until the Enter key was hit. Then you have a book called The Work, which saves the result of our try parse method, which checks to see if I can take this string and convert it into an integer and then NPA into or variable number. Then if that did work and our bull work was equal to true, then we want to have them parsed that by calibrating our user input string into an integer value and then setting our number variable equal to that light. Once again, remember that this was unnecessary because this was already done for us in the tripe parse method. If and when it returned trail. Wherever we have this here to kind of signify the tribe parsed methods use. And for another example, I have for you here using the parse method. And lastly, we went ahead and printed to the console. So just to show you what would happen if we were to type something else like we did before? Let's go ahead and run our program and type Hello. Now because this wasn't in your format, meaning we didn't type in an integer number. What happened was worked, was Landsat equal to false because this method returned false and this here and never ran. Then just to show you something. And let's go ahead and create a flow called number two and set that equal to 0. And then we'll do a float try parse. And then we need to make sure that we're changing what we're attempting to output a two to number two. As this now needs to accept the float. Then down here, we'll say float parse. And we'll explicitly convert this whole method and turn it. Now, I know we've explicitly turned floats into N2O4. I just wanted to show you that you could do the same thing with an entire method output. So let's go ahead and run our program and type something like 8.9. Now prints out eight. So because we type then a float value, our float dot try parse method, return true, which means that this code here ran. Then we took our input, convert it to a flow, and then converted that whole thing to an end. Now because an integer only holds whole numbers and truncated the 0.9 and just made it eight. Anyways, let's look for this video. And the next video, we're gonna be talking about loops. So thanks for watching, and I'll see you in the next one.
37. Chapter 7 (Loops): Intro To Loops: In this video, we're going to be talking about loops. Loops are a way to iterate through a section of code multiple times. The general syntax is as follows. You're gonna say while a condition is true, run this code. Now, I'm sure you can think of multiple reasons why you might want to use a loop, but I'm just gonna go over a few examples. You might want to print out a number a 100 times. Let's say you're making a shooting game and have the three round burst gun. You could have run three times. You might want to run some code continuously while a button being pressed. Now there are multiple types of loops that have their key differences. And you'll want to use whichever one is best for your situation. And you'll be learning about the different types in the upcoming videos. Anyways, in the next video, we're gonna be going over our very first loop, the while loop. So thanks for watching, and I'll see you in the next one.
38. Chapter 7 (Loops): While Loops: In this video, we're going to be talking about the while loop. The syntax for a while loop is as follows. You're gonna say while. In parenthesis, you put the condition that you want to check. And then you'll have the code that you want to run. So to test this out, let us go ahead and create an nth column number and set it equal to 0. Then let's say we wanted to print out the numbers 0 through ten. We could say, well, open parentheses, number is less than 11. Close parenthesis, opened and closed curly bracket. So the first thing you wanna do anytime you create a loop is get in the habit of making sure that this condition will eventually become false. Otherwise, this code is going to run indefinitely and crash your program. What you wanna do, but say number plus plus semicolon. So now that our numbers going to slowly increase every time this code is ran, I know that numbers eventually you're going to be greater or equal to 11, making this code false so that my program can continue forward above our number plus, plus. And I go ahead and print out number. And the reason I like to make sure that I'm gonna make this condition false before I do anything else is because if you forget this and you crash your program, let's say you didn't save and you just did an hour or two worth of work and your program crashes. Now what you're gonna have to do all that work again, he's like did just make sure I'm preventing that immediately. So now it's going to happen is when our program runs and it's gonna create an integer variable called number and set that equal to 0. Then it's gonna go to this while loop and it's going to check this condition. So it's gonna say is number less than 110, less than 11. Yup. So it's going to go ahead and print out 0. Then it's going to add one to a number. Now number equals one. Then once it reaches the end of my while loop, it's going to go ahead and check this condition all over again. So it's gonna say is one less than 11? Yep, go ahead and print out one. And we're going to add another one to number. And that number is two, is two less than 11, yup, all the way until it gets to 11, then it's gonna say as 11, less than 11. No. And then it's gonna continue forward. So I'm gonna go ahead and print out and wildlife. So whenever you run our program, it should print out 0 through ten. And then it's going to say and the while loop. The reason this happens is because once it sees that this condition is true and begins running our loop, it's going to continue running with this loop until this condition is false. So let's go ahead and run our program. Make sure we're now, as you can see, it printed out 012345678910. And early. And just like an if statement, you can put whatever kind of operations you want inside of here. And it's just going to check if it's true. And if not, this code just isn't going to run. So let's go ahead and start this at 11 and run our program. As you can see, it just printed out and a wildly. Anyways, that is it for this video. And the next video, we're going to be going over a do-while loop. Now what I'd like for you to do is go ahead and save this code, because we're gonna go ahead and use it again in the next video. Thanks for watching, and I'll see you in the next one.
39. Chapter 7 (Loops): Do While Loops: In this video, we're going to be talking about a do while loop. Now, the difference in syntax for a do-while loop is as follows. You're going to say do. And then the code you want to run is gonna go right after. So it's gonna be do code to run. And then while condition is true. And the difference between how this works and how our previous code ran is that we're going to tell it where we want it to do, no matter what. So what it's gonna do it. So it's gonna go ahead and run this code once. Then it's going to say while this condition is true, I want you to keep running this code over and over and over. And let's go ahead and see this in action. Let's go ahead and remove our while loop here. And then we're going to say do console dot write line number. And under that, we're going to say while. And M parentheses will say number less than 11. And then a semicolon at the end. I'll read condition. Then, like I said before, immediately, as soon as I created a loop and a condition, I like to make sure that that condition is going to equal false at some point because I don't want to crash my program and I doubt you do either. So I'm gonna go ahead and enter number plus, plus. As you notice, we got an error. And that's because now that we are working with multiple lines of code, we need to go ahead and define our code block. So let's put an open and a closed curly bracket. Then let's go ahead and set number back equal to 0. So now when this code runs, what's going to happen? Say, OK, we're creating an engineer called number and setting it equal to 0, then I can tell you for me to do something. So I'm gonna go ahead and do it. It's going to go ahead and print out number. Then it's going to add one to number. Then it's going to say, oh, I see you have a condition here that omega check. So it's gonna say number one at this point. Is that less than 11? If it is. Okay, I'm gonna go ahead and run this code again. Otherwise, if this was false, I know we're done here and I'm gonna continue forward. So if we were to run our program now, we're going to print out 0 through ten, just like we did before. Except the difference here is that this is running once, no matter what. So what's going to run our program? As you can see, we print out 0 through ten and then end a while loop, just like we did before. Now, to show you the difference here, let's go ahead and change this to 20, right off the bat. Now, notice that our condition checks of numbers less than 11. But because we're using a do while loop instead of a while loop, we're telling it we want it to do this, at least one. So let me go ahead and run our program again. And notice that we're gonna go ahead and print out number. And we're going to add one to number no matter what. And then we're going to stand up while it. So when we run our program, it's gonna say 20 and a wild loop. All right? And that's the difference between a while and a do-while loop. We want it to do something at least once and then check if the condition is true before running it again. Anyways, that does it for this video and the next video, we're gonna go over a for-loop. And just like we did before, I want you to go ahead and save what you have here so that we can use it in the next video. So thanks for watching, and I'll see you in the next one.
40. Chapter 7 (Loops): For Loops: In this video, we're going to be talking about for loops. So the syntax for a for loop, as those fellows were gonna say for open parentheses. And then we're going to have an initializer semicolon, followed by a condition, semicolon followed by an iterator. And lastly, we're going to have the body of her foreloop. So let's go ahead and print out the numbers one through ten, just like we did before. Except this time we'll be using a for loop. So let's go ahead and remove our do-while loop. And I'm gonna go ahead and remove the syntax for that as well. And we can even remove our int number entirely. And I'll show you why here in a second. So to create our for loop, we're going to say for open and close parentheses. And then below that, we're going to have open and close curly bracket done inside of our parentheses. We're gonna go ahead and create an initializer, which is basically just the variable that we want to work with. So let's go ahead and say int i equals 0 semicolon. Now you can make those variable whatever you want. But traditionally, when working with a for-loop, people use the letter i as sort of an abbreviation for index. Next, we need our condition. So what do we want to check for? What see if i is less than 11, just like we did before. And lastly, we need an iterator. So remember how before we were increasing our number by one just to make sure that our condition, would it be true forever. We can put that right here. Say I plus, plus. And then notice that you don't need a semicolon at the end of your iterator. Now, we'll just go ahead and print out. So now what's going to happen when it comes to this for loop is it's going to create the integer i. And just remember, loop variables are only available within this block of code. Same what a held true for any variables. We wouldn't create it in our while loops are do-while loops, then it's gonna check if i is less than ten. And yes and 0 is less than ten. So it's going to go ahead and run this code. Then once this code is done running and it's going to iterate through and increase i by one and then check this code again. If it is still true, it's going to continue running once this condition is false. And we'll go ahead and break out of this forum. So I'm gonna go ahead and change the wording done here in just a little bit and then run our code. And as you can see, just as we did before, we printed out 0 through ten, and then it says n-doped. Now the stuff up here, you don't technically have to have it. And they'll show you that now. So I could have created an Int i up here. And then as long as they leave that semicolon there, I can just get rid of this and run my code and it'll work just fine. The only difference is now that my variable is declared that the method level, instead of inside my loop, I can go ahead and use eye down here if I wanted. And as you can see, my program runs just fine. Same goes for this one here on the end. If I wanted to go ahead and get rid of that entirely, I could actually just put that inside of my loop. And now that's going to work the exact same way as it did before. Now though, you can delete the condition here. I wouldn't recommend it is now because there is no condition, it's essentially just going to always be true. And this is going to run forever. So I'm not gonna do that. Anyways, let us up for this video. And the next video, we're gonna talk about nesting loops. So thanks for watching, and I'll see you in the next one.
41. Chapter 7 (Loops): Nesting Loops: In this video, we're gonna talk about nesting of loops. Now just like you can nest FL and else-if statements inside of one another. You can do the same with loops. And you can even use both interchangeably to show those. So let's go ahead and create two integer variables. Let's say int num one equals 0. And now I'm to ecosystem. Then we'll say, wow, num one is less than 11. Console dot write line num one. However, read before I'm one, let's go ahead and add a string and just say num one colon space. And then don't forget the plus sign in between the string and the variable. Then below this, let's go ahead and say if num one is equal to five. And then inside of our if statement, let's create another wildly. And we'll say, well, none p2 is less than 11. Console dot write line. And then we'll just copy what we had before. And we'll just change are shrinking variable accordingly. Now remember, we want to make sure that both of our conditions are going to equal fossil at some point. So down here, let's say num one plus, plus and plus one, and we'll say num two. So it's going to happen when we're in our program. We're gonna print out num 1011, etc. Until we get to five. We're going to print out num 20 through ten, and then we'll print out the rest of them won six through ten. And we run a program. And you can see that that's what happened. Anyway, is that does it for this video. Go ahead and save this code because we're going to use it in the next video. And the next video, we're gonna talk about break statement. Anyways, thanks for watching and I'll see you in the next one.
42. Chapter 7 (Loops): Break Statements: And this video, we're gonna talk about break statement. So what a break statement is, is that it is a statement that breaks you out of a loop. So if n here, we were to say break semicolon, what's going to happen is once we print out num 15 and this condition here becomes true, we're going to start this loop. Then after we print out num to 0, this break is going to break us out of this loop immediately, and we'll go back to this loop. Let's go ahead and run our program. And as you can see, we printed out num 10, 3-5 num to 0. And then because of our break statement, we broke out of this loop and immediately printed out 600 times. So you'll want to use a break statement anytime you want to break out of the loop early. Or if you had an infinite loop, you could use a break statement to break out of it at some point. In the next video, we'll be talking about the continuous statement. Anyways, thanks for watching and I'll see you in the next one.
43. Chapter 7 (Loops): Continue Statements: In this video, we're gonna go over the continue statement and continue statement as a way to immediately go through the next iteration of the loop. So to represent those, let's go ahead and create an nth column number and set it equal to 0. Then I'm going to show you how this works in two different loops. So let's say while number is less than 11. And then we'll say number of plus plus to make sure condition will eventually be false. And then we'll print out numbered then in-between these lines. So let's go ahead and create an if statement. Say If number is equal to five, we're going to print out. And then we'll say number plus equals two. And then below here, let's go ahead and put in a continue statement below our while loop. Let's go ahead and recreate those as a for loop. So we'll say for i equals 0, i less than 11, i plus, plus. Now one thing I want you to know is that this iteration here, it could be plus plus I, and it wouldn't really make a difference in this case, since we're not storing it anywhere. We can even say minus, minus i or i minus minus. Then we'll print out i, but the sound, let's just go ahead and do it on the same line. So we'll say console.log right eye. And I'll create a string and we'll just put a comma space and a semicolon at the end. Then we'll say if i is equal to five, we want to go ahead and print out i and then increase i by two. So say hi plus equals. And then we'll go ahead and use the continue. Also, one thing I want to let you know is there anything you can do with a for loop? You could do with a while loop. But most of the time this is a little easier to read, especially if you're going to be iterating through something anyways. And another way to determine which to use, as, let's say, you know, how many times you want to iterate through something, you should probably just use a for loop. And if you're not sure and you just want to check for a condition to see if it's true, and then continue running code until that condition is false, I'd use a while loop. Otherwise, just use what was most readable to you for your situation. So what's happening here is we have an integer called number and we have it equal to 0. Then we have a while loop that checks whether a number is less than 11. What's going to happen is it's going to print out number on a separate line. And then it's going to check if number is equal to five. If not, it's going to continue through and just increase number by one and check this condition again. Once it is true, it's going to print out number again. So essentially we are going to be printing out 0 through five. Then we're going to end up printing out five. Again. Then we're increasing number of I2. Number will then be equal to seven and then are continue statement says we want to go ahead and stop the loop, check for this condition again. And then, depending on whether or not that is true, run through our code. So basically what we're doing as stopping the lib here and then checking our condition to see if we're going to iterate through again. Then down here in our for loop, we're basically done the same thing except we created i and set it equal to 0. Then we check if i is less than 11. If it was, we went ahead and ran this code. Only differences here. We're not printing out i on a separate line. We're printing it on the same line, followed by a comma and a space. Then we're increasing i by one and checking this condition again. Afterwards we're running back through. Once i is equal to five, we're printing out I again, meaning will be printing out five twice. We're going to increase i by two, making it seven and then are continue statement. And a for-loop is actually going to run our iteration again. So instead of i being equal to seven, i is going to equal eight and then print out 910. And as you can see, when we run a program, that is what happens when we printed out 0 through five and another five through time. Then we printed out 0 through five and another five on the same line. Then because there were console dot write line, it brought us down to another line and we printed out the rest. So 8910. Notice that we skipped ahead by three and let us, because our for loop runs the iteration again, Monday you use a continue statement. Whereas our while loop doesn't have a built-in iterator and therefore at only skipped ahead and by the two that we specified. Now just to show you that doing plus, plus I would create the SIM result. Let's go ahead and do that and run the program again. And as you can see, it didn't change a thing. I wanted to show you that we are checking this condition again and not just running through our code blindly. Same goes for the wildlife. So let's just go ahead and set number equal to 11. And we'll do that for both of them. Now, when we run our program, once we had five and print five again on each one, it's going to go ahead and stop our loop. So as you can see, they both stopped half-life. And one more thing that I wanted to show you is that down here, I does not exist. And that is because the variable was created within our loop. The reason we didn't do the same with our while loop here, because how do we put int number equals 0 inside of our loop? Every time our code ran, we'd always be creating a new integer called number and setting it equal to 0, which would cause this to be stuck in the loop parameter. However, we can access number down here, and that is because it was defined with an r method. Anyways, let us up for this video. In the next video, we're going to be talking about random numbers and programming. So thanks for watching, and I'll see you on the next one.
44. Chapter 8 (Random Numbers): Random Numbers In Programming: In this video, we're gonna be talking about random programming. A computer to understand which represent on, because you can't technically get a random number from a computer. So what do I need a random number? You use a special equation to try and represent a random number as much as possible. This is done by inserting different numbers into this equation. And by inserting different numbers into the equation, you can get seemingly random result. That seems random is also known as a pseudo random number. However, to keep things simple, people just call it a random number. Now, I have no idea what this equation is. Fairly complex. And you don't need to either. What is important, however, is knowing how it works and that it works. So in the next video, we're gonna go ahead and create our first random number. So thanks for watching, and I'll see you in the next one.
45. Chapter 8 (Random Numbers): Getting A Random Number: In this video, we're going to be creating a random number, or at least seemingly random. To do this, we need to create a sense of the Random class. Just says right now they are working within a class called program. There's a class called random that has an equation for creating random numbers. So to use this class, the first thing we have to do is create an instance of it. To do that, we're gonna type random, which is the name of the class, followed by a name we wanna give our instance. Let's go ahead and call this diurnal. So, so far we specified the type we want, which is of type random or the class name. We gave it a name. And now we're gonna set it equal to a brand new instance i with a random class. And then you need open and close parentheses and a semicolon at the end. So like I said, what we've done is we've created a new random class instance called Tyrone. Remember this name here is just based on the name of the class that we're creating an incident up. Then we're setting it equal to a brand new random with open and closed parentheses. We'll get into this more later when we get into classes. Just know for right now and for those how we create a new instance of a class. Next, let's go ahead and ask the user how many times they would like to roll the die. So say console dot write. How many rolls, thrones Create a new collaterals and set that equal to 0. Let's also create a new string called input and set that equal to a blank string. Then we'll create a bool cold work and set that equal to try parse. And then end parenthesis. We're gonna say input comma out rules. Then assuming that worked, we want to go ahead and set it equal to whatever the user typed in. So we'll say it if we're, then we went to set rolls equal to nth dot parse. And then we wanna put our input. And then we'll create a while loop. And we'll say, well roles as greater than 0. Then inside of here, let's say int number equals. And then we're gonna say die roll, which isn't the instance of world-class dot and this dot or period, and this is the member access Operator, Sir accessing part of the Random class here. And we're gonna say next with a capital N, and then open and close parentheses and a semicolon at the end. Now inside of these parentheses, we need to insert the range of numbers we want to get out of our random result. So say one comma six, a six-sided die. Then below here, let's go ahead and print out numbers. Now, I'm gonna go ahead and add in some pseudo-code. So up here I'm gonna say Create Random class instance will say asks for row count. Then we'll say convert row count two integer. And lastly we'll say print out result of rules. And then one thing we wanna do is actually set our string and put the console dot read line. And after a console dot write line number, we're gonna wanna say gross minus, minus. And this way will eventually break out of our robot way. Then we'll go ahead and run a program. And it's gonna ask how many times we want to roll. I'm gonna go ahead and say ten. And as you can see, I printed out ten different numbers. And if I were to go ahead and run this again, you can see that they're all different numbers. So let's go ahead and say something like a 100. And you'll notice that for whatever reason we did not get the number six. The reason for this is because of the random classes. Next method takes the minimum value and then the maximum Kio, whoever the maximum value as exclusive. So what you actually want to do and change seven. And now if the school include numbers one through six. So if we ran it again and typed on a 100 and hit Enter, you can see that now we get various numbers from one to six. So real quick, I'm going to comment this out and just go over this with you one more time. So to get a random number, you don't honestly random. Give it a name. Equals new random, open and close parentheses and a semicolon. Then you'll want to store the number somewhere. So I'll say int number equals. And then we'll say die roll. As listeners are classroom since name dot next, open and close parenthesis felt by the minimum value comma, and then the maximum value we went plus one. So if I were to say one comma London, we could get any number from one to ten, followed by a semicolon at the end. Then we'll just go ahead and print out number and run our program and we'll get a random number between 110. And they go. Another way. We could have done this to the set of four int i equals 0 semicolon, i less than 11 semicolon I have plus ones. And then instead of her Farley, because it aside console dot write line gyro dot next comma 11. And now we will print out 11 random numbers between 110. And you go. Anyways, that's it for this video. And the next video we'll be talking about collections. So thanks for watching and I'll see you in the next one.
46. Chapter 9 (Collections): Intro To Collections: In this video, we are going to be talking about collections. Now, when I say collection, I'm just referring to grouping variables together. This is different than the actual definition. I like collection in C sharp, which we'll get into here in a minute. So you have two main ways of grouping variables. You have arrays and then you have collections. Now, the main difference between these two as arrays are best used when you know the exact amount of variables that you want to store and collections for storing the dynamic variables. Now let's talk about why you would want to encrypt tradables in the first place. So let's say I wanted to store three whole numbers. Now we can do what we've done in the past. And N1 equals 0, equals 0 and equals 0. Now this works fine, but what if I had ten, 50, or even a 100 of these? And as I'm sure you can guess, it would quickly get out of hand. For one, typing up a 100 variables would take forever. Then if I wanted to print these out, I have to type them all up again. Also, I just don't have a great way of working with all of them together in general. And this is where grouping variables comes in handy. This is because both arrays in collections have multiple methods which you can utilize to work with all of your variables. They also allow you to create multiple variables at the same time without having to go through and create each one individually. Anyways, that does it for this video. And the next video we're gonna go over a single dimension arrays. So thanks for watching, and I'll see you in the next one.
47. Chapter 9 (Collections): Arrays: In this video we're going to be talking about single dimension, alright? Or mark, commonly referred to as just an array. Now the syntax for an array as those fellows. And it's going to be the data type, followed by open and closed square brackets, then the name, then an equal sign or the assignment operator, followed by nu. The data type again, open square bracket, the size, close square bracket, and a semicolon. You may notice that this looks similar to when we worked with the Random class. And that is because we're working with the array class. Once again, we'll get into classes more in later on. But for now, just know that this is how you're going to create a new array. So to keep things simple, let's go ahead and create an array to store three full members. So we're gonna say an open square bracket, close square bracket, numbers equals new. And open square bracket, close square bracket, semicolon. And now we have an array, the whole three integer variables. By the way, the variable is created in your array are gonna automatically default or initialized to a value as close to 0 as possible. So right now we have three integer variables that you will 0. And to prove this, let's go ahead and print out all of these out. Now to access a variable within an array, all you have to do is you're going to need the name followed by open and closed square brackets. And then inside those square brackets, you're going to need the index. Now, array start there indexing at 0. So if we wanted to print these out, we can say console dot write line. Then we'll just say numbers. And then square brackets. We're going to say 0 in order to print out our first variable. Then we'll just do the same thing for the other two. So now when our program runs, we're gonna create a new integer array called numbers. And that's going to hold three integer variables. And then we're going to print out all three of those integer variables on separate lines. So let's run our program. But you can see that we printed out 03 times. Now what if we wanted to change whatever variables here were equal to? We will change them just like we would any other variable. First, we're going to write in what we're talking about. So let's say we wanted to change our first variable. We'd say numbers, open square bracket 0, close square bracket equals, let's say ten. And now our first variable and R into re is equal to ten. Let's go ahead and set the other to equal the numbers as well. So saying numbers one equals five and numbers two equals 27. Then let's go ahead and print them all out again. I'm just going to copy and paste this code above. And you can see they've printed out 03 times and then 10527. Now let me just show you what would happen if we tried to access a variable and r array that did not exist. So say console dot write line numbers three. So because our array only has three variables and their index at 012, then there is nothing index three. And as you can see when we run our program, we're gonna get an error here. And it says that the index was outside the bounds of the array. Now I'm gonna go ahead and show you another way we could have done this. So let's go ahead and comment all of this stuff. And this time we're going to create the same exact array and set the number is equal to the 10527. Again, have our, we're going to do this all on one line. To do this, we're going to say int opening, close square bracket numbers equals new int opened and closed square brackets again. And then instead of putting the size in there, we're just going to put two curly brackets afterwards, and then a semicolon at the end. Now inside of these curly brackets, we're just gonna go ahead and insert the values 10527. And what this was going to do is it's going to go ahead and create a variable for each value that we type in and then set it equal to the value that we type. And because we were working with an int array, they're all gonna be integer variables. So I can say ten comma five, comma 27. And now let's go ahead and copy this code above. And then I'm just going to uncomment these lines down here and run a program. And as you can see, it printed out 10527, just like before, except we created this on one line. This is another way of initializing arrays that you may find more useful depending on your situation. Now, like I mentioned in the last video, both arrays in collections have multiple method which you can utilize to work with your collection of data. Show you an example of this. Let's just go ahead and write console dot, write line, numbers, dot. And as you can see, a whole list pops up here. And let's just go ahead and click on this, the length of the capital L. And now when we run our program, it's going to print out these three numbers here. And that's going to print out three being the size of our array. Now, there is a bunch of different methods that you can use, both with arrays into collections. And then it would take forever for me to go over all over them with you. So I highly recommend you look him up and just kinda glance through them so that you're aware of what's out there in case you were to ever need it in the future. Because there are multiple methods which you can utilize. The check things like the size F0 value is already within your group of variables. There are methods for sorting and a lot more. Anyways, that does it for this video. And the next video we're gonna go over multidimensional arrays. So thanks for watching, and I'll see you in the next one.
48. Chapter 9 (Collections): Multi-Dimensional Arrays: In this video, we're going to be talking about multidimensional arrays. Now, I found these pretty confusing when I first started. So I'm gonna go ahead and just kinda show you how a multi-dimensional array is laid out, as well as the syntax for r one. So hopefully when we start working with it, you'll understand it a bit better. Now in this example, we're going to be working with two-dimensional arrays. The maximum amount of dimensions you can have as 32. Now, odds are, you'll probably never need that many dimensions. And as you can imagine, that would be pretty complicated anyways. So the syntax is as follows. We're gonna say datatype, followed by an open square bracket, comma close square bracket. Then we're going to say the name equals new. Datatype. Opens her bracket. How many rows? Comma, how many columns? Close square bracket and a semicolon at the end. Now, this can be visually represented like so. On the first row, you're going to have 0 comma 00 comma one, then 0 comma two. And then on the next row you're going to have one comma 01, comma one, one comma two. And finally, you're going to have two comma 02, comma 12, comma two. So let's go ahead and create a two-dimensional array, the whole three rows, just like we did up here. Now, we can have as many rows and columns as we want it. But this would just be easier to visualize and work with when starting out. So we'll say nth, open square bracket comma close square bracket will say numbers equals new. And open square bracket comma three, close bracket semicolon at the end. So now we have an array of integer variables that is indexed lake. So now let's say we wanted to access the variable at this middle index here. Oh, you'd have to do is say numbers. Open square bracket, one comma one being our index. And then we can set it equal to five, for example. Now, we could go through and initialize each one of these individually to whatever we wanted. Otherwise they will default to 0. Or we could initialize them originally when we created our array. So let me go ahead and show you how that's done. First, let's go ahead and comment this out. Then I'm gonna say open square bracket, close square bracket, numbers equals new int, open square bracket, comma close square bracket. Then just like we did in the last video, we're gonna go ahead and create a set of curly brackets. And then simply insert the values which we want to initialize our variables to at the various indexes. So let's say we wanted to create an array of this size here and give each one of these a value from one. Nine. First we create another set of curly brackets to represent our first row. Then inside I'm gonna say one comma two, comma three. And then I'm gonna put a comma after that set of curly brackets and create another set. This will represent our second row. Lingo, say four comma five, comma six. And then I'm going to do it one more time. And say 78 comma nine. Then make sure you have your final curly bracket, as well as the semicolon at the end. Now, we could have made this as big as we wanted. I just wanted to represent what I had up here to make it easier for you guys. So now 00 or this one here is going to be equal to 101, will be equal to 202, will be equal to three. Because let's say here represents our first row, and each one of these represents a different column. This one here represents our second row. So these will be 456, and this one are third row. So the Zotero 789. Notice that we once again started at index 0 for both the rows and the columns. Now, what if you wanted to print out each of these values and this type of format, let me go ahead and show you how you can do that using surely. We're going to say four. And then to make things easier to read what's go ahead and say int rows equals 0. And while rows as less than three, because that's how many rows are in our array. And almost say rhos plus plus. Then inside of the for loop, we're just going to create a, another for loop. So we'll say for n columns equals 0 and then walk columns as less than three columns plus, plus. Then inside that for loop, we're going to say console dot, write numbers, open square bracket, rows, comma columns. And then don't forget the semicolon at the end. Now, remember we couldn't name these variables, whatever we want it. I'm just naming them rows and columns to hopefully give you a better visual understanding of what we're doing here. Then below that for loop. And in our first for loop, we're going to say console dot write line. And just leave it at that. And now let's go ahead and run a program quick. And you can see that we've printed out 123 on one line, 456 and another, and 789 on the next. And if you're unsure why this happened, let me go ahead and go over this with you. So when our program ran and it created a new two-dimensional integer array called numbers. Then we give it three different rows, as well as three different columns. And then we set those values equal to 123. Okay, so this one equal to 123456789. Then in our for loop, we created a new integer called Rose and set equal to 0. And we said, Wow, Rouse is less than three. And then every time I ran through our upper lip, we wanted to increase, rose by one. Now we set this number equal to three and based on how many rows we had. Then inside of that for loop, we created another for loop with an integer called column my set that equal to 0. Then we said, well, cams is less than our total number of columns being three. And then every time I ran through, we wanted to add one to columns. Then inside of that Farley, If we wanted to just write out numbers being our array, rows, comma columns. So the first time through Rose was equal to 0. N columns was equal to 0. So it's going to print out one. Then this for loop isn't done. So it's going to run again. And when it runs again increases columns by one. So our Rose was still 0 in columns was now one. And now it's printing out this index here being the value two. And then it did the same thing, but increased columns again. So now we're printing out the index 02. Then once this was finished, we went down to a new line. Rose was increased by one. We did it all over again. So now our rows here, there's going to be one. So we're going to be printing out the value at index 10. Columns will increase, 1-1, cams increases again, 12, etc. And we do that one more time. Anyways. But does it for this video. And the next video, we're going to be talking about less, which is going to be our first collection. And it'll allow us to work with a group of variables and dynamically change the amount of variables within it. Thanks for watching, and I'll see you in the next one.
49. Chapter 9 (Collections): Lists: In this video, we're going to be working with our press collection being list. Now, unlike arrays, let's allow you to work with a dynamic amount of variables. So you want to use them when you are unsure of how many variables you'll need or when you'll need to add or remove variables. I, well, the syntax for list is as follows. You're gonna say list. The less than symbol, the datatype. The greater than symbol, followed by the name, an equal sign or the assignment operator. New list. The less than symbol again, followed by the data type. The greater than symbol, open and close parentheses and a semicolon at the end. Notice that we did not specify the size, and that is because there is no need to. So let's go ahead and create a less the whole three whole numbers. And I'm going to show you a few methods you can use in the list class to work with your group data. So we're gonna say list with a capital L less than and greater than. Numbers equals, new, list, less than and greater than, open and closed parentheses, and a semicolon at the end. Then all we have to do is add in three integer values that we want in our numbers list today. So we're gonna type the name of our less being numbers, followed by the member access operator for a period, followed by add with a capital a, as this is the name of the method. Open parenthesis, the value. And we want to answer, I'm gonna go ahead and say it 33. Close parentheses and a semicolon at the end. And we're gonna do the same tensor tumor numbers. Let's go ahead and enter at 6699. Then we can access these values the same way we did with our array. So let's say I wanted to print out all three of these on separate lines. And you can say console dot write line numbers, open square bracket 0 or the index and the very first variable, close square bracket. Then I can go ahead and copy this twice and just change the index here, 212. Now when I run my program, it's going to print out 33, 66, and 99. Then I just wanted to go ahead and show you a few more methods we can use with our lists. So let's go ahead and say console dot, write line numbers, dot count. And this is going to print out three as the size of our list. So I'm just gonna go ahead and add some pseudocode here. We'll say print sign. Then I'm going to create a blank line by just saying console dot write line. Then let's say I wanted to remove one of the values from my list. Well, I could say numbers dot mu, open parentheses, and then I can just type in the value that I want to review. So let's say I wanted this to look for the value 66 and our movement. 66, close parentheses and a semicolon at the end. Then I'm gonna go ahead and print down number is at index 01. Again. However, I'm not going to print out number is at index two because now there won't be a third index. So I'm going to say console dot, write line numbers, open square bracket, close square bracket, and do the same, print X1, and run our program. And as you can see, we've created a list called numbers that have integer values. We added the values 33, 6699, which are automatically sent to the indexes 012, is that is the order in which they were added. Then we printed them out on a different line. So he said thirty three, sixty six, ninety nine. Then we printed out how many values where NR list using the count method, which was three. Then we remove the value 66 from our list. So from the first occurrence of that value and remove it. Then we printed out number is at index 0 again and numbers and index one. We're now 33. And then because 99 was now the next value is 66 was removed and printed out 99. Now, another way of printing out values in a collection of variables like this would just be to use a for loop. We could say for i equals 0, i less than. And then we can just put in how many values are gonna be in the collection. And instead of putting in a static number, we can just based on whatever it is. So you'd say numbers, dot count, and that way, and we're always working with the correct size. And let's say I plus, plus. And then inside the for loop will say console dot write line numbers. And then inside of our square brackets, we're just going to answer, I am just going to go from 0 to one less than the max value. So in our case, so it's gonna go from 0 to one because there's only two values, which is perfect because those are the indexes in our collection. When I run a program, you can see that we're going to print out 3399 twice. And I'm just gonna go ahead and move this one here. And then to show you that this would work for up here, let's just go ahead and remove this as well, and copy our for loop. And then when we were in our program, you can see that that works just as it did before. Then I'm going to go ahead and add some pseudocode for may often statement here. And I'm going to say for mu first occurrence of value. Now we also have another way of removing values from our collection using the remove method. And what this does is it removes a value at a specified index. To do this, we're going to say numbers. Remove that with a capital RNA. Open and close parentheses and a semicolon at the end. And inside those parentheses we're gonna simply insert the index. So let's go ahead and insert the index one. And I'm gonna go ahead and comment out our numbers dot remove line up above. And now when we run our program, and it's going to print out thirty-three, sixty six and ninety nine. It's going to print out the count. Again being three. It's going to create a blank line. And then we're removing the value at index one, which is going to be 66 because we have 012. And just like before, if we copy and paste our for loop, it's going to print out 33 in 99. And as you can see, it does exactly what it does here at the end. Now once again, there are multiple methods you can utilize what's collections. And I'm just going over some of them with you. But they still highly encourage you to go and look at all of them for yourself, seeing what's out there. Then I'm gonna go ahead and remove everything except for our list and the three values we added, just to clean things up here. So let's quickly go over just a couple of more methods. First, give the clear method, which removes all of the values from your left. To do so, you simply type numbers clear, followed by open and close parentheses and the semicolon at the end. Then I'm gonna go ahead and add another value, two or less. So I'm gonna say numbers, add ten. And I'm gonna go ahead and print out all of the values and unless using a for loop. So I'm gonna say for int i equals 0, i less than numbers dot count I plus, plus. And then I want to print out numbers index i. Now when we run our program, you can see that it's only going to print out ten. And that is because it is the only value and our numbers list. Now what if I were to come out this value here is going to simply print out nothing. Notice that we did not get an error. This is because numbers was now equal to 0. Because 0 is not less than 0 are surely didn't even run. Making this a safe way to print out the values in your collection. Then the last month that I wanted to show you is the insert method, which inserts an element at the specified index in the list. First, let's go ahead and remove this code up here. Then T is they insert method. We're going to say numbers, dot insert, followed by an open parenthesis and the index we want to insert it at. Let's go ahead and say one comma, the value. I'm gonna go ahead and say 22. Close parentheses and a semicolon at the end. So currently we have the value of 33 and index 066 and index 199 and index two. And let me go ahead and add a few comments here just to help show that. And now when we add in the value of 22. And then next one, what's going to happen is 33 is going to stay at index 022, is going to become the new index1. And then 6699 where we pushed downwards, making 66 index 299 and X3. Then let's go ahead and run our program. And as you can see, we've printed out 3322 because this was an X1, 66. And then lastly, any night. Anyways, that's it for this video. And the next video we're going to be working with the collection class, which stores elements in a first-in, first-out style. Thanks for watching, and I'll see you in lecture one.
50. Chapter 9 (Collections): Queues: In this video, we're gonna be talking about the queue collection type, which stores variables and a first-in, first-out style. Now the syntax for a queue is as follows. You're gonna say Q, the less than symbol, followed by the datatype. The greater than symbol than the name, followed by an equal sign or the assignment operator. Q. The less than symbol, Q, less than our data type again. And the greater than symbol, open and close parentheses and a semicolon at the end. Then let's go ahead and create a queue, the stores three whole numbers. So say q, less than and greater than. Numbers equals Q, open and close parentheses and a semicolon at the end. And notice that this looks exactly like a list, except we say queue and instead alleged. Now let's go ahead and add in three numbers. And I just want to remind you that you can name your collections whatever you want, and you can have any data type as well. So I'm gonna go ahead and say numbers. Dot n q as this is how you add a file to a queue, open parentheses. And I'm just gonna give it the value, one, close parenthesis and a semicolon at the end. Plan and create another one and set that you will have a tail and another one equal to three. Now, remember that a queue stores variables and a first-in, first-out style. You may see this ran as FIFO, FIFO. So what does this mean exactly for us? Well, it means that when we access values from our queue, we're going to get the very first one we put in to show you this. We're gonna go ahead and print out the first value put into our queue, or the value at index 0. So I'm gonna say console dot write line numbers with a capital P and open and close parentheses. Now when we run our program, it's going to print out one as this was the first value inserted. So the peak method returns the object at the beginning of the queue without removing it. Then I'm gonna go over the dequeue method with you. This is the main way in which remove values from your queue. So I'm going to say console dot write line numbers, dot dq with capital D, open and close parentheses. So when our program runs, it's going to create a queue, which in our case is a collection that holds integer values. Then we are going to enter these three integer values into it. Or an enter one at index 02, at index 13, at index two. Then we're gonna go ahead and return the object of the beginning of the queue. But we don't want our movement. We just want to look at it. Alright, we just want to peek at it. So it's going to print out one. Then it's going to run this dequeue method. Now what the dequeue method does is it's going to not only returned the object at the beginning of the queue, but it's going to remove it. Well, then I'm gonna go ahead and comment that out. And I'm gonna go over another method with you, which is just the clear method which we've used before. So I can say numbers that clear with the capital C, open and close parentheses and a semicolon at the end, unless you remove all of the objects from the Q. K works just the same way as it did with the list. Anyway, singling out and comment that out and add some pseudocode here. Remove all objects from a. Then let's just go ahead and print out the rest of the values and our queue. To do this, I'm gonna go ahead and create an integer and set it equal to the total amount of values in the queue. And I'll explain why in a bit. It's going to say n objects in numbers. And set that equal to numbers dot count. Then I'm going to say for int i equals 0, i less than objects in number I plus, plus. And then I wanna print out numbers dot dq. Now, just to point something out, quake, technically this count here as a property and not a method. This was why it doesn't have parentheses at the end of it. Now, we will be going over properties later on. So right now, do not worry about it. I simply wanted to make you aware of why it looks different. Now the reason we did this is because how do we set our condition to be i less than numbers dot count. The problem is it would constantly changed every time our for loop brand because we're removing one from numbers. So let's say we went ahead and set a integer equal to the amount of values in our numbers Q. Yes, we could have just typed three here. However, if we ever wanted that change, our Q, and this would work dynamically. Then let's go ahead and run a program. And as you can see, it's going to print out one because we peak data here and then 123 as they were removed. And notice that this dequeue method doesn't take an index at all. It just simply returns and removes the object at the beginning of the queue. And that is one way you can tell that we are in fact removing these values as because we didn't insert an index. And that's just removing the first object. You can see that the first object subtly change from one to two to three as each of these was removed one of the time. Anyway, so that is it for this video. And the next video, we're gonna go over a similar collection. However, this one is called a stack and a stores values in a first in, last out style. Anyways, thanks for watching, and I'll see you in the next one.
51. Chapter 9 (Collections): Stacks: In this video, we're gonna be talking about the stack class. Now, a stat collection is used to store values in a last-in, first-out style. The syntax for a stack, as those fellows, you're gonna say stack less than symbol, datatype greater than symbol. How by the name. Then the equal sign or the assignment operator. New stat. Less than symbol, the datatype again, greater than symbol, open and close parentheses and a semicolon at the end. Let's go ahead and create a stack. The holds three whole numbers. We're gonna say stack less than, greater than numbers equals new stack less than, greater than open and close parentheses and a semicolon at the end. Notice that this looks exactly like a queue except this stack instead. And just remember that a stack stores values and a last-in, first-out style. Now to add values to our stack, we're gonna use the push method. So we're gonna see numbers, dot push, open and closed parentheses, and a semicolon at the end. Then in-between our parentheses, we're simply going to insert a value. So, so say 24. Then I'm going to copy this twice. Then for the second value, I'm going to say 67. And last one, I'm gonna say 98. Now, you can imagine a stack, a stack of cards, or a stack of blocks, whatever works for you. So I can say bottom card, middle card, top card. And this is where this last-in, first-out comes in play. So imagine if I had a stack of cards and I set down my first card, my second card, and my third card. Now I know these numbers aren't really in a deck of cards, but bear with me. Now when I pick up these cards, I'm a pick him up in a last-in, first-out style, right? Pick up the top card, then the middle card, done the bottom card. So the first method we're gonna go over again is the count method. So let's go ahead and print that out. Let's say console dot write line numbers, dot count. And this is just going to print out three because that's how many elements are objects in our collection. Here are our stack. We also have the clear method which removes all of her objects from the stack. So I can say numbers clear. And this would remove all of the objects. Now, just like we had in the queue, we also have the peek method. So I could say console dot write line numbers dot P. And now when I run my program and set up a printing out 24, like it did in the queue. It's going to print out 98. And that's because it stores things in a last-in, first-out style. So just like a deck of cards, if I wanted a peak, I'd be peaking at the top card or the last one I put down, which is going to be 98. Okay. So we printed out the size of our stack being 39, printed out 98 being the tab card. And we just peaked at it, right? So imagine if you're handling a deck of cards, any peak at the top card. If I peak as the top card, again, it's not going to change. So if I copy and paste this line here and run our program again, and it's gonna say 98 twice. But what if I populate card right out of the deck? I can do that using the pop method. I can say console dot write line. Remember is dot pop. And then search with a capital P with open and closed parentheses. Now at this method does here is it's going to return the object at the top of the stack and remove it. All right, so it's just going to pop it right off the top. So if I were to pop this top card off the deck, now, this is my top card right? So far to peak again. So it's a console dot write line PQ. What's going to happen is first we're going to peak at a card and it's going to print out 98. Then we're gonna peek at it again, and it's obviously going to be 98. Then we're going to pop the top card right off. So we'll pop unless when I'm 98 gone, we're also returning it. So we're printing that out for us because it's an R console dot write line method. And we just written this without the console dot write line and wanted a printed to the console, it just would've been removed. So we printed out 983 times and we finally got rid of it. And now when we peek at the top of the debt, we're actually going to be looking at this 67 cuz the next card in the stat. Go ahead and run a program. Printed out the count 3983 times. We got rid of that. 98. We picked up the top again, 67. Now let's go ahead and get rid of all this extra code here after our last push. And we'll say, and we'll say int objects in numbers, numbers, dot count. Then we're gonna create a for loop, just like we did before. And we're going to say int i equals 0, i less than objects and numbers. And once again, we're doing it this way. So this works dynamically. And because numbers dot count would constantly change as we use the pop method. So we're going to say i plus plus console dot write line numbers that pot, open and close parentheses. And when we run our program, and it's gonna say 98 because that's the top card. Get rid of it. 67, get rid of it. 24, get rid of it. And as you can see, exactly what it does. Ninety eight, sixty seven. Twenty four. Now, let's just say we wanted to peek at the top again, and there's nothing in there. Well, if I were to say numbers dot py and run our program, you can see that I get an error. And that's because the stack is empty. Lists just can't happen. Now, same type of deal. What happened with the Q? Now there are methods similar to our try parse method that we used in the past to a check whether r, q, r, stack, etc, is empty so that we know whether or not that method will run innocuous and error before using it. And once again, I highly encourage you to go through and look at all the different methods available for the different collections that we go over. Anyways, that does it for this video. And the next video we're going to be talking about for each loops, which is a loop specifically designed for working with collections. Anyways, thanks for watching, and I'll see you in the next one.
52. Chapter 10 (Foreach Loops): Intro To Foreach Loops: We're gonna be talking about for each element in a collection, a collection you are using. Now, mixing collections with loops really opens up the possibilities for you. We've already looked at printing things to console with the collection. Elliot. However, I'm gonna give you a few more examples of things you can do. For example, let's say you were making a game and you wanted a breakable glass window. When the object or the glass was shattered, you could swap it out with a similar object that is broken up into multiple pieces. Then if you have all of those pieces and a collection, you can iterate through them and not forced to them in the direction that you want. You can accordingly. And as you go through these next couple of videos, I highly encourage you to think of more ways. You can use loops and collections together. Anyways, that does it for this video. In the next video, we'll be creating a collection and working with it using a for each loop. And then I'll show you how we can do the exact same thing using a for loop. So thanks for watching, and I'll see you in the next one.
53. Chapter 10 (Foreach Loops): Foreach Loops & (Loops & Collections): In this video, we're going to be talking about mixing loops in collections and also creating our very first for each loop. So the first thing we're gonna do is create an integer array just like we have in the past, with threefold numbers. So we're going to say open and closed square brackets. Numbers equals new int, open square bracket, three, close square bracket, semicolon. Next we're going to set each one of our three integer values and our numbers array equal to 5. First, let's go ahead and do this with a for loop. So we're gonna say four, open parentheses, n i equals 0, semicolon i less than numbers dot length, semicolon i plus, plus. And then make sure you have a closed parenthesis at the end. And inside the body of our for loop, we're simply gonna say numbers. Open square bracket, I, close square bracket equals five semicolon. Then let's go ahead and print out all of the values in our array using a for loop as well. To do this, we'll just copy and paste our for loop. Down below. Then inside the body of our for loop, we're going to erase those code here and say console dot write line numbers, open square bracket, I close square bracket. Now when we run our program, it's going to print out 53 times. Then let's go ahead and comment out folkloric for-loops. And we're gonna do the same exact thing using a foreach loop. Now real quick, let's go ahead and go over the syntax for a foreach loop. The syntax for a, for each loop is as follows. You're gonna say for each open parentheses, the data type, you want to check for. The name. You want to work with. The name of the collection, followed by a closed parenthesis. And lastly at the body at the end. Then to set all the values and our numbers array equal the 5. First, we're going to have to go ahead and create a variable to iterate through the index of our array. So let's go ahead and say int i equals 0. Then we'll create our foreach loop. So we're gonna each. Then, because our array works with integer values, we want to say for each and then copy the element name. We'll simply say number in numbers. And then opened and closed curly brackets down below. So let me kinda go over how this works with you. We're basically saying sure, each integer in our numbers array, we want to create a variable called number and set that equal to the element which our loop is currently looking at. So. I'm going to say numbers. Open square bracket. I close square bracket equals five. Then on a separate line, I'm going to say i plus plus semicolon, then a for each loop as kinda run one time for each element it found of the data type that you wanted it to check for. So now our loop is basically going to say numbers indicate 0, set that equal to five. Then it's going to increase i by one. And do it again. And then it's gonna do it one more time. Because there's three total elements in our array, the integer data type. And it'll say numbers two equals five. Then let's go ahead and print out every single element in our array, just like we did before using a foreach loop. And we're gonna go ahead and do this in a separately again. So we're going to say for each open parenthesis. And what does say num in numbers? Close parentheses, open and close curly brackets. And then inside of here, we're simply gonna write console diary line num. And now when we run a program, it's going to print out three times just as it did before. Now, let's go ahead and look at the differences between our for-loop and a for-each loop. First, let's start with assigning each value equal to five. So in our for loop, we were easily able to create a temporary variable for us to work with for index. Also, we were able to run our code as many times as we want it based on a condition rather than for each element in the collection of the data type we specified. Then we bring it with either increase our index by one outside of our code. Which is why I find that a for-loop is much more readable and a better suited for assigning values to a collection. That's what they're for each leaf, we had a creative variable outside of our loop, in our case, making it available everywhere within our main method from its declaration done to this closing bracket down below. But other than that, the code is fairly similar. And also, if you remember, in the last video, I showed that a for each loop creates a copy of the collection and then uses that for its operation. Which is why we didn't simply set number equal to five as this one. I'm going to actually change the values of our collection. This only what a change that current value number. By the way, this name here can be whatever you want. Just realize that this is what you'll be using to work with the elements in your collection. Also, it is a local variable. Therefore, we could use the same name twice. How do we want to do? Now, let's look at the differences for when we printed out the values in our collection. In this case, I personally find that the for-each loop looks a lot cleaner. For one, a reader of your code can immediately tell. So we wanted to do something for every single element in our integer array as we have our entry here. And we said that we wanted to work with every integer value and our numbers array. Then we didn't have to bother. Creating a variable that work with for index or specifying the index at all. Because a for each loop simply created a copy of every single value in our numbers array and name that copy numb. For each iteration of our loop. We are simply able to say console dot, write line num and print out each of the values in our array. Whereas with our for loop, maybe create a variable to work with for index. Then we had to say that we went to doing crease this index value by one after each iteration. Basically setting our index equal to every value from 0, numbers dot length minus one. As our condition checks the i is less than numbers not win. Then we printed out members at index i. So whether or not you want to use a for loop or a for each loop is just going to depend on your situation. But when simply wanting to do something with your collection, other than changing the values directly. Normally, I use a for each loop. So if we now you have a bit of understanding between the differences of the using a for-loop and a for-each loop, as well as an understanding of how to create a for each loop of your own. Lastly, I just wanted to show you what I meant when I said a for each loop, clones a collection for its operation. To do this, I'm simply going to change those code here. So I'm gonna say number equals five. And as you can see, we get an error. And it says that I cannot assign to number because it is a four each iteration variable. Which is why for us to assign values to our collection. We have to do it this way and directly work with the value at a specified index in our collection. By the way, if we were just using an array as an example, we could have used a another datatype, such as a class or a float, or a double, etc. Now I know you guys don't know a whole lot about classes or objects yet, but we'll be getting into them in the last chapter coming up here shortly. And I just wanted you to be aware that it was possible for future reference. Now here's a few more differences between a for loop and a for each loop. Now a for each loop, really isn't it best when you want to modify the array itself? As you can see here, the for loop is much cleaner. Also, a foreach loop only iterates forward, whereas with the for loop, we could iterate backwards. For example, to do this, we could have said int i equals number dot length minus one. And then over here said I minus minus, and then change sir condition accordingly. Lastly, let's go ahead and create one more for each loop to determine the highest value in our collection. First things first, I'm gonna go ahead and delete this for each loop, index i integer. Then I'm going to change the size of the array to be a 100. And then I'm going to set each of the values in our array equal to random number. To do this, I'm going to create a new instance of the Random class. So I'll say random num value. Random. Then we'll create a for loop to say each of the values in our array equal random number. So we'll say for i equals 0, i less than numbers dot link i plus, plus. And then said earlier, we're simply going to say numbers equals num value. And actually let's go ahead and rename our random class instance to random value just to make it more clear what we're breaking one. So a right-click on it, click rename, and then we'll simply edit the name. So I'm gonna say random value and I enter. And as you can see, a change both instances. If you're not working in Visual Studio, you'll have to change them separately. Then we're going to create an integer variable called max value, Masada equal to 0. And lastly, we'll create a for each loop to check for the highest value in our array. So we'll say for each value in numbers. And then we want to check if a value is greater than our current max value. So we'll create an if statement and say, if value is greater than max value, then we simply want to change max value equal to value. So now when we run our program, we are going to be creating a new integer array called numbers that holds a 100 integer variables. Then we create a new instance of the Random class called random value and recite each of our values, our array equal to a random value. Then we create an integer called max value that we wanted to hold the highest value in our array. To check for this, we created a foreach loop called value. And we said for each integer and our numbers array, we wanted to check if the value or the current element we are working with an array is greater than max value. And remember r for each loop only iterate forward. So essentially what we're saying is if numbers at index 0 is greater than max value, then we're going to set max value equal to value. And then we do this again for index one through 99. Then we printed out all of the values in our array. Then just sorting out, working with insanely high numbers. Let's go ahead and inside of our parentheses here, um, our next method. And we'll go ahead and say 0 comma 101. And now we're only working with numbers between 0. And lastly, at the bottom, I'm gonna go ahead and print out maxval here. You're going to say console dot, write line. And then quotation marks. I'm going to say highest value colon with a space. And then I'm going to max value. Then when I run my program, we're going to print out a 100 numbers between 0. And we're going to print out our highest value, which in our case was a 100. And as you can see, we have a 100 right here. Now, if we run it again, you can see that our highest value this time was only 99, as it appeared here. Anyways, that is it for this video. And the next video, we're going to be talking about another collection being a dictionary. So thanks for watching, and I'll see you in the next one.
54. Chapter 10 (Foreach Loops): Dictionaries: In this video, we're going to be talking about another collection called The Dictionary collection. And then C sharp, it basically works the same as an English dictionary, where you have a collection of keys and values. The queue would be the word and the value would be the definition. And you can use these, restore all kinds of things. For example, you could use it to store items in the game where you have the name of the item ID, you can use it to create a phonebook where you could use their name as the key and their phone number has the value exedra. Anyways, let's first go over this syntax for a dictionary. So you're gonna say dictionary less than p, data type, value, greater than, followed by the name, the equals sign for the assignment operator. Then new dictionary, less than the key data type again. Comma the value data type again, greater than opening, close parenthesis, and a semicolon at the end. Then, for the sake of simplicity, let's go ahead and create a dictionary. And it works just like a phone book. So we're gonna say dictionary less than now and I'll say string comma lung, which has a larger version and an integer variable. The greater than symbol. And we'll call this fun but nail dictionary. Less than string again, con left long and again, the greater than symbol, open and close parentheses, and then semicolon at the end. So now that we have our phone book, let's go ahead and add three names and numbers to it. Now by the way, just so that there was with the rest of the collections, there are multiple methods that you can use what the dictionary, and I highly encourage you to look them up. See, you know, what is available to you. But let's go ahead and go over a few of them. So the first one we're going to use here is the add method. So one of the type in the name of our phone book, so it knows what we're referring to, which in our cases, phonebook dot or the member access operator. Then we're going to say Add, look a capital, a, open parenthesis. Say in quotations. John Glenn, after our quotation marks were gonna say comma. Then we'll say 555555555510 of them altogether. And go ahead and do the same thing again. So for this one's will say Jane comma, and then we'll do 107. Land-holding this one last time. Sally And we'll do 109. Now to access a value inside the heart dictionary. Instead of inserting an index, we simply want to give it the key. So for example, let's say console dot, write, line, phone, book, open square bracket. And then we'll say John. Then a close square bracket at the end. And now when we are in our program, it's going to actually print out 510 times because this is the value associated with a key. Jon. Now what if I wanted to print out every single item inside of our dictionary here? Well, the easiest way to do this would be to use a for each loop. So let's go over how to do that right now. We're going to say for H and M parentheses, we're gonna say key value pair with a capital at the beginning of each word there. The less than symbol. Then we're going to simply copy the data types that we used for the key and the value. So I'll say string comma lung, the greater than symbol item. And we'll say n number. Then in the sight of our foreach loop will simply say console dot write line. Then we'll say item value with a capital V. Now when we run our program and it's going to access the value inside of each of our key value pairs, which is what a dictionary's stored. So currently and we have a dictionary called fun bug. The stores key-value pairs, including a string and alone. So now we're saying for each key value pair and my string, and along in our phone book, we want to create a replica called item. So sorry we said console dot write line item, and then we got the value out of it. So now we're going to simply print out all three of these values. Notice that we've printed out high as ten times, twice, and that's because we also printed up here. You can also use item.quantity to print out the key, and I'll show you that now. So change lists the key with a capital K and run a program. And as you can see, we've printed out John Jane sound. Now, let's just make this look a little nicer here. So in quotation marks, and we'll say name, colon, open curly bracket, closed curly bracket, number, colon, open curly bracket, one, close curly bracket. And after a quote will say comma item.quantity, item.name. And I'm gonna go ahead and insert a backslash t just to create a little more space there so that it looks a little nicer. Then I'm gonna go ahead and go over three more methods with you. The first one we're gonna go over, isn't there a remove method? To remove an item? You're a dictionary. You're simply going to say the name removed. And then end parenthesis, just taped the key. So we can say John, for example. Then if we copy and paste our foreach loop. And what's delete this console dot write line up here. You can see that when we run our program, we printed out John, Jane and Sally. Then I'll meet Jane and Sally as John was removed. Then our last team methods are going to check whether a key exists or whether a value exists inside of our dictionary. Key exists equals false. And I'll say value equals false. Then we'll simply say contains key with a capital C and K. And then in parentheses, we're gonna type in the key that we want to look for. In our case. Let's go ahead and say Sally. Inside of her statement. Let's go ahead and print out key. So what's happening here is it's going to look in our dictionary called phone book. It's going to check if it contains a key using this contains key method. And it's going to check whether it contains the key. Sally. If it does contain the key, then we want to print out key access. But before we print out keys us, we want to change it to true. So I'll say kx equals true. Then let's just go ahead and copy and paste our IO statement down below. And instead of contains key, we're gonna say contains value. And in this one, we're gonna go ahead and check for 107. Now, as you can see, it automatically lets us know that value as a long, and therefore, we can't answer this string here because you cannot convert from a string to alone. So we go ahead and delete that. And then we'll insert ten 7s. Now to avoid any errors, I'm just gonna go ahead and copy and paste our value from up above. And we want to change our bull here to value exists. And set that equal to true. If the statement is true, then let's take one last look at our program. So first we created a dictionary called phonebook that holds a string for a key in a long, for a value. Then we added the three key value pairs, but using the add method. So you add the key Jon with a phone number of all fives. And we did the same with chain and Sally and gave them their own values. Then we said for each key-value pair of a string and along in our phone book or a dictionary, we wanted to write out name followed by the item's key. Then we wanted to print out number followed by the item's value. Remember that we only said item because that is the name we gave up here and our foreach loop. Then we use the remove method to remove the element with the key john fen, we copy and pasted our foreach loop. Notice that we were able to use the same name twice. This is because this is actually a temporary variable being used in reference to the copy and lard collection during our for-each loops operation. Then we created a bull called co-exist and set it to false. The another bull called devalue exist and set that to false. When we said if it contains the key Sally, We want to cite key exists equal to true and then print out key exists. Then lastly, we said if fun but contains those value of ten sevens. So we want to set value exists equal to true. And then we actually want to print out the value exists. Right? Now, when we run our program, we can see that we printed out all three of her elements in our dictionary. Then, because I removed John, we only printed out Jain and silent. Then we printed out true twice as both the key and the value of ten 7's also gives us, anyways, that's it for this video. In the next video, we're gonna be talking about enums. So thanks for watching, and I'll see you in the next one.
55. Chapter 11 (Enums): Intro To Enums: In this video, we're gonna be talking about enums are the enumeration. Not only is this a new datatype pressed to work with, but it is also our first user defined data type. And we'll go over how that works and how that comes into play in the next video. And this is basically a named constant. And if you remember, a constant is a variable that cannot be changed. So for example, we can't, and let's just call this number equals ten. Now, if I were to try and change number two, you can see that I get an error. And that's because this is not a regular variable. Meaning once it is defined, that cannot be changed. Also note that they must be given an initial value. So I couldn't declare it and then initialize it later. Now, personally, I found it extremely hard to understand when I first started, which is why I put them off till this point. So that hopefully there'll be easier for you to understand. And I can give you a good example of how and when they're useful. Anyways, that does it for this video. And the next video, we're gonna go ahead and create our very first. So thanks for watching. I'll see you in the next one.
56. Chapter 11 (Enums): Creating An Enum: And thus what we're gonna be creating our first the_num. Now the syntax for an ENM is as follows. You wanna say hello by the name, an open curly bracket. Then you're gonna have your first named constants, then your second named constant judgement. And each of your constants there's going to be separated by a comma. Then lastly, you're gonna have a close curly bracket at the end. So let's go ahead and create an ENM that holds a list of weapons. So we're gonna say enough. Weapons. Also note that the proper naming convention for an enum and C-sharp as pascal casing, meaning we're going to start the first word with an uppercase, as well as every subsequent word and the name. Then we'll have an open curly bracket. And just like we would with any other constant, you want to use pascal casing for the names of each one of these as well. Crystal, salt, sleeper, grenade. Also, notice how we'd have an area here. That's because you cannot define an enum inside of a method. Instead, we have to define it inside of our class. So let's go ahead and cut this and paste it in our class. Now, remember how I said that an enum is a list of unnamed constants. As you can see here, when we mouse over each one of our constants, you can see that it says weapons 0.9c equals 0. The next one, so there's 1234 and it would just keep going on LinkedIn. We had more of them. So it starts at 0 and it counts up by one. And this is using the integer type. Now if we wanted to use a another integral type, we could specify it like so. After a name, we could put a colon. Then the type we want to use. For example, I could say, right? So now we have an enum called Weapons, has a bunch of named constants of the byte tight. Now remember by default, this is of type int. Alright, so I'm gonna go ahead and remove that. Next. I wanted to show you that we can actually change the values in the background of our constants. To do this. And we have to do is say equals after the name of our continent and then give it a value. So let's say I wanted to sudden 95. And now each one that we didn't define, then it's just going to count up by one. So as you can see, 9P equals 55, SL equals six, sorry, equals 57. Thanks Sandra. Now, what if we assigned a sorry, hotel guy, you as well? Let's say, Sure. Well, we're gonna go from 5556 back down to four and then it's just going to keep coming up as the rest were not defined. So it just goes off the last defined constant and then adds one to each of the following. So we're going to go for sex. Next, I'm going to show you how that access any of them. So for example, let's say we wanted to print out sniper. I can say console dot write line. Then I simply type the name of my enum, followed by the member access operator or a period. And as you can see, a list of all of my constants. So there's just going to pop up for me. And I can just scroll through these using the arrow keys. And I can see those value associated with them as well. So I wanted to print sniper. I could either click on it or hit enter. And then just run my program. You can see printed out right there. So another thing to know as the Visual Studio automatically put all my constants in alphabetical order for me in this list. Next, I'm going to show you how we can go from an enum back to1 and has led us the data type that we're using to do this. Let's say int weapon equals. Then we want to do a cast. So we're gonna need to open and close parenthesis. Then we want to convert it to an int. So will simply type int inside of our parentheses, followed by weapons or the name of bringing them dot, then we simply select one. So let's say I wanted to get the value of assault rifle. And you can see right here this four. They're the semicolon here at the end. Then we'll just print out weapon. Now when we run a program. And you can see that we've printed out sniper four. Notice that when we indirectly accessed our enum, that we got the string value of rate constant. Next we're gonna go over how to go from an int to any of them. So first we want to create an instance of our enum. So I'll say weapons. We'll call this primary. And we'll set it equal to the cast weapons held by a value. In this case, we'll say for now we're going to pick this integer thing, the value for, cast it, the type weapons. Then it's gonna find assault rifle, is that as our constant with a value four. And it's going to put it inside of our instance of our enum called primary. Notice that we made this variable just like we would any other, started with a data type thing of type weapons, followed by the name. Then we can simply print out. And as you can see, we've printed out this. Alright, well, now what if I went to, went with a constant value that wasn't in our enum list. Well, let's try it. Let's go ahead and set our 47 and run the program. Now has you see, all it did was it actually just print it out. And that's because we made an instance of our enum called primary. And then we just set it equal to a constant value. However, it doesn't have a spring or a name associated with it. And therefore, it just printed out seven. Now, but if we tried to give it a value that it cannot hold like 7.2, for example. And ran our program, it would have just been casted to an integer type. That's another slip types that are in m holds. So as you can see, a truncated off the 0.2 and we simply printed out seven. You can see that that is what is happening by changing this to something like 7.9 and running the program again. And I will still print out seven. Anyways, I'm gonna go ahead and remove all over those code except enum itself. And we're gonna go ahead and create an array of our enum type. So we'll say buttons, open square bracket, close square brackets. We'll call this primary agains equals new weapons, open square bracket, and we'll say three to give it a size. Close square bracket, and I'll give it a semicolon at the end. Then we simply assign the weapons in our array to values just like we would any other array. So we'll say primary open square bracket 0, square bracket equals weapons dot a salary from, for example. Then what's going to print out all of the values in our weapons array. Just to show you what it would look like. We'll simply say for each weapons, for the type we want to work with. Then from my element clone name, I'm going to simply say weapon in primary. And all I wanna do is print out weapon. Then I'll run our program. And as you can see, we printed out a SHA rifle and then we print it out 0 twice. And that's because there is no constant are enough here. That has the value 0. But what if I were to change grenade equal to 0, giving our 0 constant a string to associate yourself with. Well, we can run our program again. Now you can see we not printed out assault rifle and Len grenade at twice. Anyways, does it for this video. And the next video, we'll be talking more about how enums are useful, as well as going over an example that shows us exactly why they're useful. So thanks for watching, and I'll see you in the next one.
57. Chapter 11 (Enums): Using Enums: In this video, we're gonna be going over an example that shows us exactly how the NY Times are useful, as well as talking about when you should be using any of them. Many times when you have a list of values and you only want to be able to set something equal to one of them and the values will be constant. You're going to want to use enums. This is because they're more readable than an actual list of constants. And because it protons, a lot of possible errors, which you'll see here in a bit. So let's go ahead and go over an example of this. First, let's create our Ina. So we're gonna say weapons, open curly bracket. And I'll say nine. Assault rifle, sniper, shotgun. And we'll put a close curly bracket. Now, let's say this was a list of weapons you have in your game. And you can use this for days of the week or a west of items, a set of dog breeds or whatever you wanted. But we're just going to use this as an example. Now, let's say you wanted to do different things based on what weapon character was holding. Now, you might be wondering, why can't we just use a string? Well, let me show you. So let's say I said string, my weapon. But a set of quotation marks and