‫Welcome back.
‫In this video, I would like to give you a little bit better of an understanding of what's happening
‫with all of those console methods that we are using and that we are going to use quite a bit in the
‫future.
‫So I just want to give you a little bit of a background information.
‫Most of what you are going to see is not going to be relevant if you just want to use it.
‫But if you really want to understand what's going on, then this is the right video for you.
‫So let's get started.
‫So the thing is, there are various methods available in that console class and we are going to look
‫at the ones that are relevant in order to input something and in order to get an output.
‫All right.
‫So we're going to look into that.
‫So let's get started.
‫First of all, we have this console, right?
‫And this prints and keeps the cursor on the same line.
‫So basically this allows us to print something onto the console and we can see it.
‫So if we use this code here console, right, and within brackets and quotation marks, we have text
‫here.
‫What this code would do is it would print text here onto our console and we can then see that that is
‫especially useful when you have some values that you want to display and see if your code actually worked.
‫And this is very useful, especially as a beginner when starting to program, so that you can actually
‫see what your code does and it will output something.
‫So right is one way of doing something.
‫So there is this class called console and this is predefined within C-sharp, so we can just use it
‫and this allows us to basically use its methods.
‫And one of those methods is right.
‫Okay.
‫So if we want to write something, we can use console dot, right?
‫And then within brackets and within quotation marks, we enter whatever we want to display on the console.
‫But there is another way we can also use right line and this prints and puts the cursor in the next
‫line.
‫So when you use right line instead of right, it will do the same thing.
‫It will also print the text onto the line where it was, but it will also do a line break, so to speak.
‫So it puts the cursor onto the next line.
‫Okay, so that's the only difference between the two.
‫And then we have console that read.
‫This takes a single input of type string and it returns an ASCII value of that input.
‫So it returns an integer value.
‫So string is just one type of data, it's the text type and int is the numbers type.
‫So the whole numbers type, we're going to look into strings and numbers and the two to different types
‫in a lot of detail later on.
‫But for now, just remember, strings are for text, integers are for numbers.
‫Now you might wonder, what is this ASCII that Dennis is talking about?
‫Well, ASCII stands for American Standard Code for Information Interchange.
‫This is a seven bit character code, which basically allows us to use characters and interpret them
‫by the computer.
‫So the computer basically interprets whatever we enter.
‫So, for example, scrolling all the way down and a which is the character and symbol A internally is
‫this value here as a.
‫Binary value.
‫So as binary value is 015 zeros one.
‫And as a decimal value is 65.
‫So in total there are 256 values inside of this ASCII code table and 256 because it starts at zero all
‫the way up here.
‫This is just a little side note.
‫You don't really need to remember any of that.
‫It's just for you to know if you want to understand a little better what this ASCII even means.
‫So that is not just a random word that you have heard, but also that you have a little bit of an understanding
‫what's going on here.
‫So now there is another method called red line, which takes a string or an integer input and returns
‫it as the output value.
‫So.
‫The Dodd method.
‫What it does is it takes the input as ASCII or returns it as ASCII value, but the red line returns
‫the actual output.
‫So whatever we have entered will also be returned.
‫And by return we I mean we can then reuse it in our code.
‫So basically this allows us to write code where the user has to enter something into the console and
‫that can then be used to do some calculations or actually run the program.
‫That's very useful.
‫So whenever you want to have user input, this is very helpful to this console about red line.
‫And then there is also red key.
‫This only takes a single.
‫Character, so takes a single input of type string and it returns the key info.
‫So details about the key that was entered will be returned.
‫And now you can decide what you want to do with that.
‫All right.
‫So now let's look at some sample code, because all of this theory is good and all.
‫But it sometimes just makes sense to look at actual code and see how that actually works.
‫So here we can see we have this static void main, which is our main entry point for our class and our
‫project in general.
‫So here we have a line of code which says console dot, right line.
‫Hello, welcome.
‫So this prints the text and jumps to a new line.
‫That's what this code will do.
‫But then we have also console that, right?
‫And here we say hello.
‫This also prints the text in the same line, but it doesn't jump to the new line.
‫And then we have console.
‫Right.
‫Welcome.
‫Which is the same as hello.
‫Only that the text that is displayed is different.
‫So now let's also use console read key, which basically just waits for us to enter a key once again.
‫So this basically just blocks our program from stopping or from finishing, and that's what we can use
‫quite often, or what we will use quite often in order to keep the program running without shutting
‫down.
‫Depending on your settings.
‫This is not necessary, but in most cases it will be required.
‫So I'm just going to keep it here.
‫So basically this just leaves our program open so that we can see whatever is printed onto the console.
‫Otherwise the console would close very quickly and we wouldn't even see what the result was.
‫Okay, so now let's look at the output here.
‫Okay.
‫So the output will be hello, welcome.
‫So this is printed as a result of console right line and then we will have hello, welcome together
‫in one word print as the result of our to console right statements because console right doesn't create
‫any empty spaces.
‫That doesn't create an additional line break if we don't specifically instruct it to do so.
‫So here I want to show you an example for the red line method and also for the red key method.
‫So we have at the main method once again, inside of the main method, which is our entry point here,
‫we have the right method which says Enter a string and press enter.
‫So the user will be seeing enter a string and press enter.
‫Then in this line here we take the input of the user by using console dot red line and we store it inside
‫of red input.
‫And then what we do is we use console that bright line in order to display whatever the user has entered.
‫So we say you have entered and here we use curly brackets, zero curly brackets and right input.
‫So basically what we are doing here is we say you have entered and then whatever the user has entered.
‫So this curly bracket, zero curly brackets, we'll just use whatever comes after the comma here and
‫will replace itself with the entry that is inside of this variable here.
‫And then we write Enter a string and press enter.
‫So here we used the console that read method and we use int ASCII values.
‫So we store it in the variable called ASCII values or whatever the user enters.
‫And then we just say whatever the user has entered here.
‫So we say ASCII value is and then the actual ASCII value of the value that the user has entered.
‫So now for you as a little exercise, you use that code and play around with it.
‫Just see what the output will be.
‫Just going to give you a quick example here.
‫So here, what we have is we enter a string and then press enter.
‫So in my case, I'm just entering.
‫Dennis And it will just say You have entered Dennis then it will say, enter any key and press enter.
‫So I'm just going to press the D and it will return to ask the value of that entered value, which is
‫68.
‫Now, if we look here and we go to line 68, we can see that it is, in fact, the Uppercase RD.
‫All right.
‫So that was it.
‫That's a little introduction to the console class and how we can use some of the methods.
‫If you want to know more about the different methods of that console class, you can of course check
‫out the documentation.
‫Here you will find the console class and there you can see that there are a bunch of methods.
‫So when you go to the methods, you can see be clear, move buffer read key read lines.
‫So the ones that we know are read, read, key re line and then the right one.
‫So right and right line.
‫But you can see there are a bunch more set window positions at window size and so forth.
‫So if you want to know more about a specific method, you can just click on it and you will see Red
‫Line.
‫What does it do?
‫Well, there are a bunch of overloads.
‫What is an overload or an overload are many different versions of the same method that have different
‫input options.
‫So here we can have an input of three different values.
‫So a string, an object and an object.
‫We will see later on what objects are and how that works.
‫But basically the red line that we use is this bright line here where we just enter a string and if
‫you want to know more about it, you can just click on it and you will see that it will return a void
‫or return nothing.
‫So it writes a specific string value followed by the current line terminated to the standard output
‫string.
‫All right.
‫But as I said, we will look a lot more into that later on.
‫It will make a lot more sense.
‫So don't worry if you didn't understand every single part of it and don't worry about memorizing all
‫of that, we will just use those methods quite extensively.
‫And and that will become very natural later on.
‫All right.
‫So see you in the next video.