1 00:00:00,180 --> 00:00:01,000 ‫Welcome back. 2 00:00:01,020 --> 00:00:05,970 ‫In this video, I would like to give you a little bit better of an understanding of what's happening 3 00:00:05,970 --> 00:00:10,560 ‫with all of those console methods that we are using and that we are going to use quite a bit in the 4 00:00:10,560 --> 00:00:11,130 ‫future. 5 00:00:11,130 --> 00:00:14,490 ‫So I just want to give you a little bit of a background information. 6 00:00:14,490 --> 00:00:18,300 ‫Most of what you are going to see is not going to be relevant if you just want to use it. 7 00:00:18,300 --> 00:00:22,710 ‫But if you really want to understand what's going on, then this is the right video for you. 8 00:00:23,520 --> 00:00:24,960 ‫So let's get started. 9 00:00:24,960 --> 00:00:30,990 ‫So the thing is, there are various methods available in that console class and we are going to look 10 00:00:30,990 --> 00:00:35,670 ‫at the ones that are relevant in order to input something and in order to get an output. 11 00:00:36,060 --> 00:00:36,450 ‫All right. 12 00:00:36,450 --> 00:00:38,220 ‫So we're going to look into that. 13 00:00:38,220 --> 00:00:39,360 ‫So let's get started. 14 00:00:39,960 --> 00:00:42,840 ‫First of all, we have this console, right? 15 00:00:42,840 --> 00:00:46,560 ‫And this prints and keeps the cursor on the same line. 16 00:00:46,560 --> 00:00:52,950 ‫So basically this allows us to print something onto the console and we can see it. 17 00:00:53,070 --> 00:00:59,790 ‫So if we use this code here console, right, and within brackets and quotation marks, we have text 18 00:00:59,790 --> 00:01:00,300 ‫here. 19 00:01:00,450 --> 00:01:09,360 ‫What this code would do is it would print text here onto our console and we can then see that that is 20 00:01:09,360 --> 00:01:16,050 ‫especially useful when you have some values that you want to display and see if your code actually worked. 21 00:01:16,050 --> 00:01:21,390 ‫And this is very useful, especially as a beginner when starting to program, so that you can actually 22 00:01:21,390 --> 00:01:24,540 ‫see what your code does and it will output something. 23 00:01:24,990 --> 00:01:27,690 ‫So right is one way of doing something. 24 00:01:27,690 --> 00:01:35,640 ‫So there is this class called console and this is predefined within C-sharp, so we can just use it 25 00:01:36,060 --> 00:01:39,720 ‫and this allows us to basically use its methods. 26 00:01:39,720 --> 00:01:42,480 ‫And one of those methods is right. 27 00:01:42,540 --> 00:01:42,770 ‫Okay. 28 00:01:42,900 --> 00:01:46,290 ‫So if we want to write something, we can use console dot, right? 29 00:01:46,290 --> 00:01:52,470 ‫And then within brackets and within quotation marks, we enter whatever we want to display on the console. 30 00:01:52,560 --> 00:01:58,230 ‫But there is another way we can also use right line and this prints and puts the cursor in the next 31 00:01:58,230 --> 00:01:58,620 ‫line. 32 00:01:58,620 --> 00:02:02,670 ‫So when you use right line instead of right, it will do the same thing. 33 00:02:02,670 --> 00:02:10,800 ‫It will also print the text onto the line where it was, but it will also do a line break, so to speak. 34 00:02:10,800 --> 00:02:13,260 ‫So it puts the cursor onto the next line. 35 00:02:13,830 --> 00:02:16,590 ‫Okay, so that's the only difference between the two. 36 00:02:16,980 --> 00:02:19,770 ‫And then we have console that read. 37 00:02:19,770 --> 00:02:26,550 ‫This takes a single input of type string and it returns an ASCII value of that input. 38 00:02:26,550 --> 00:02:28,950 ‫So it returns an integer value. 39 00:02:28,950 --> 00:02:36,450 ‫So string is just one type of data, it's the text type and int is the numbers type. 40 00:02:36,450 --> 00:02:42,780 ‫So the whole numbers type, we're going to look into strings and numbers and the two to different types 41 00:02:42,780 --> 00:02:44,550 ‫in a lot of detail later on. 42 00:02:44,730 --> 00:02:50,070 ‫But for now, just remember, strings are for text, integers are for numbers. 43 00:02:51,820 --> 00:02:55,900 ‫Now you might wonder, what is this ASCII that Dennis is talking about? 44 00:02:55,930 --> 00:03:01,630 ‫Well, ASCII stands for American Standard Code for Information Interchange. 45 00:03:01,990 --> 00:03:07,810 ‫This is a seven bit character code, which basically allows us to use characters and interpret them 46 00:03:07,810 --> 00:03:08,650 ‫by the computer. 47 00:03:08,650 --> 00:03:11,380 ‫So the computer basically interprets whatever we enter. 48 00:03:11,410 --> 00:03:20,110 ‫So, for example, scrolling all the way down and a which is the character and symbol A internally is 49 00:03:20,110 --> 00:03:23,200 ‫this value here as a. 50 00:03:24,200 --> 00:03:25,760 ‫Binary value. 51 00:03:26,240 --> 00:03:30,260 ‫So as binary value is 015 zeros one. 52 00:03:31,360 --> 00:03:33,880 ‫And as a decimal value is 65. 53 00:03:33,880 --> 00:03:48,610 ‫So in total there are 256 values inside of this ASCII code table and 256 because it starts at zero all 54 00:03:48,610 --> 00:03:49,480 ‫the way up here. 55 00:03:51,160 --> 00:03:52,960 ‫This is just a little side note. 56 00:03:52,960 --> 00:03:55,630 ‫You don't really need to remember any of that. 57 00:03:55,630 --> 00:04:01,120 ‫It's just for you to know if you want to understand a little better what this ASCII even means. 58 00:04:01,120 --> 00:04:06,310 ‫So that is not just a random word that you have heard, but also that you have a little bit of an understanding 59 00:04:06,310 --> 00:04:07,480 ‫what's going on here. 60 00:04:07,810 --> 00:04:13,780 ‫So now there is another method called red line, which takes a string or an integer input and returns 61 00:04:13,780 --> 00:04:15,550 ‫it as the output value. 62 00:04:15,550 --> 00:04:16,330 ‫So. 63 00:04:17,200 --> 00:04:18,850 ‫The Dodd method. 64 00:04:18,850 --> 00:04:26,800 ‫What it does is it takes the input as ASCII or returns it as ASCII value, but the red line returns 65 00:04:26,800 --> 00:04:28,170 ‫the actual output. 66 00:04:28,180 --> 00:04:31,420 ‫So whatever we have entered will also be returned. 67 00:04:31,420 --> 00:04:36,450 ‫And by return we I mean we can then reuse it in our code. 68 00:04:36,460 --> 00:04:42,550 ‫So basically this allows us to write code where the user has to enter something into the console and 69 00:04:42,550 --> 00:04:48,340 ‫that can then be used to do some calculations or actually run the program. 70 00:04:48,910 --> 00:04:49,960 ‫That's very useful. 71 00:04:49,960 --> 00:04:54,910 ‫So whenever you want to have user input, this is very helpful to this console about red line. 72 00:04:55,120 --> 00:04:57,070 ‫And then there is also red key. 73 00:04:57,100 --> 00:04:59,290 ‫This only takes a single. 74 00:05:00,210 --> 00:05:06,030 ‫Character, so takes a single input of type string and it returns the key info. 75 00:05:06,030 --> 00:05:09,000 ‫So details about the key that was entered will be returned. 76 00:05:09,000 --> 00:05:11,820 ‫And now you can decide what you want to do with that. 77 00:05:12,210 --> 00:05:12,630 ‫All right. 78 00:05:12,630 --> 00:05:17,580 ‫So now let's look at some sample code, because all of this theory is good and all. 79 00:05:17,580 --> 00:05:23,320 ‫But it sometimes just makes sense to look at actual code and see how that actually works. 80 00:05:23,340 --> 00:05:30,120 ‫So here we can see we have this static void main, which is our main entry point for our class and our 81 00:05:30,120 --> 00:05:31,190 ‫project in general. 82 00:05:31,200 --> 00:05:35,700 ‫So here we have a line of code which says console dot, right line. 83 00:05:35,700 --> 00:05:37,170 ‫Hello, welcome. 84 00:05:37,170 --> 00:05:40,290 ‫So this prints the text and jumps to a new line. 85 00:05:40,290 --> 00:05:41,640 ‫That's what this code will do. 86 00:05:41,970 --> 00:05:44,700 ‫But then we have also console that, right? 87 00:05:44,700 --> 00:05:46,290 ‫And here we say hello. 88 00:05:46,320 --> 00:05:52,020 ‫This also prints the text in the same line, but it doesn't jump to the new line. 89 00:05:52,720 --> 00:05:54,550 ‫And then we have console. 90 00:05:54,760 --> 00:05:55,120 ‫Right. 91 00:05:55,120 --> 00:05:55,870 ‫Welcome. 92 00:05:55,870 --> 00:05:58,150 ‫Which is the same as hello. 93 00:05:58,150 --> 00:06:00,670 ‫Only that the text that is displayed is different. 94 00:06:00,820 --> 00:06:10,570 ‫So now let's also use console read key, which basically just waits for us to enter a key once again. 95 00:06:10,570 --> 00:06:17,350 ‫So this basically just blocks our program from stopping or from finishing, and that's what we can use 96 00:06:17,350 --> 00:06:22,270 ‫quite often, or what we will use quite often in order to keep the program running without shutting 97 00:06:22,270 --> 00:06:22,690 ‫down. 98 00:06:22,720 --> 00:06:24,010 ‫Depending on your settings. 99 00:06:24,010 --> 00:06:28,000 ‫This is not necessary, but in most cases it will be required. 100 00:06:28,000 --> 00:06:29,320 ‫So I'm just going to keep it here. 101 00:06:29,320 --> 00:06:34,180 ‫So basically this just leaves our program open so that we can see whatever is printed onto the console. 102 00:06:34,180 --> 00:06:39,220 ‫Otherwise the console would close very quickly and we wouldn't even see what the result was. 103 00:06:39,520 --> 00:06:43,390 ‫Okay, so now let's look at the output here. 104 00:06:43,750 --> 00:06:43,870 ‫Okay. 105 00:06:43,990 --> 00:06:46,060 ‫So the output will be hello, welcome. 106 00:06:46,060 --> 00:06:53,200 ‫So this is printed as a result of console right line and then we will have hello, welcome together 107 00:06:53,200 --> 00:07:01,990 ‫in one word print as the result of our to console right statements because console right doesn't create 108 00:07:01,990 --> 00:07:03,580 ‫any empty spaces. 109 00:07:03,640 --> 00:07:10,060 ‫That doesn't create an additional line break if we don't specifically instruct it to do so. 110 00:07:10,060 --> 00:07:18,460 ‫So here I want to show you an example for the red line method and also for the red key method. 111 00:07:19,000 --> 00:07:25,450 ‫So we have at the main method once again, inside of the main method, which is our entry point here, 112 00:07:25,570 --> 00:07:29,530 ‫we have the right method which says Enter a string and press enter. 113 00:07:29,530 --> 00:07:33,280 ‫So the user will be seeing enter a string and press enter. 114 00:07:33,280 --> 00:07:42,100 ‫Then in this line here we take the input of the user by using console dot red line and we store it inside 115 00:07:42,100 --> 00:07:43,600 ‫of red input. 116 00:07:44,430 --> 00:07:50,750 ‫And then what we do is we use console that bright line in order to display whatever the user has entered. 117 00:07:50,760 --> 00:07:57,750 ‫So we say you have entered and here we use curly brackets, zero curly brackets and right input. 118 00:07:58,200 --> 00:08:03,690 ‫So basically what we are doing here is we say you have entered and then whatever the user has entered. 119 00:08:03,690 --> 00:08:11,100 ‫So this curly bracket, zero curly brackets, we'll just use whatever comes after the comma here and 120 00:08:11,100 --> 00:08:16,860 ‫will replace itself with the entry that is inside of this variable here. 121 00:08:17,950 --> 00:08:20,570 ‫And then we write Enter a string and press enter. 122 00:08:20,590 --> 00:08:26,800 ‫So here we used the console that read method and we use int ASCII values. 123 00:08:26,800 --> 00:08:31,060 ‫So we store it in the variable called ASCII values or whatever the user enters. 124 00:08:31,060 --> 00:08:34,450 ‫And then we just say whatever the user has entered here. 125 00:08:34,450 --> 00:08:41,470 ‫So we say ASCII value is and then the actual ASCII value of the value that the user has entered. 126 00:08:41,980 --> 00:08:47,290 ‫So now for you as a little exercise, you use that code and play around with it. 127 00:08:47,290 --> 00:08:49,780 ‫Just see what the output will be. 128 00:08:50,410 --> 00:08:52,210 ‫Just going to give you a quick example here. 129 00:08:52,570 --> 00:08:57,340 ‫So here, what we have is we enter a string and then press enter. 130 00:08:57,340 --> 00:08:58,600 ‫So in my case, I'm just entering. 131 00:08:58,600 --> 00:09:06,100 ‫Dennis And it will just say You have entered Dennis then it will say, enter any key and press enter. 132 00:09:06,100 --> 00:09:12,310 ‫So I'm just going to press the D and it will return to ask the value of that entered value, which is 133 00:09:12,310 --> 00:09:13,840 ‫68. 134 00:09:15,430 --> 00:09:22,630 ‫Now, if we look here and we go to line 68, we can see that it is, in fact, the Uppercase RD. 135 00:09:23,230 --> 00:09:23,710 ‫All right. 136 00:09:23,710 --> 00:09:24,530 ‫So that was it. 137 00:09:24,550 --> 00:09:30,310 ‫That's a little introduction to the console class and how we can use some of the methods. 138 00:09:30,340 --> 00:09:35,380 ‫If you want to know more about the different methods of that console class, you can of course check 139 00:09:35,380 --> 00:09:36,910 ‫out the documentation. 140 00:09:37,800 --> 00:09:43,530 ‫Here you will find the console class and there you can see that there are a bunch of methods. 141 00:09:43,530 --> 00:09:49,090 ‫So when you go to the methods, you can see be clear, move buffer read key read lines. 142 00:09:49,090 --> 00:09:53,940 ‫So the ones that we know are read, read, key re line and then the right one. 143 00:09:53,940 --> 00:09:55,260 ‫So right and right line. 144 00:09:55,260 --> 00:09:59,910 ‫But you can see there are a bunch more set window positions at window size and so forth. 145 00:10:00,720 --> 00:10:06,780 ‫So if you want to know more about a specific method, you can just click on it and you will see Red 146 00:10:06,780 --> 00:10:07,290 ‫Line. 147 00:10:07,290 --> 00:10:08,280 ‫What does it do? 148 00:10:08,280 --> 00:10:10,380 ‫Well, there are a bunch of overloads. 149 00:10:10,380 --> 00:10:16,920 ‫What is an overload or an overload are many different versions of the same method that have different 150 00:10:16,920 --> 00:10:18,750 ‫input options. 151 00:10:19,020 --> 00:10:22,230 ‫So here we can have an input of three different values. 152 00:10:22,230 --> 00:10:23,970 ‫So a string, an object and an object. 153 00:10:23,970 --> 00:10:27,540 ‫We will see later on what objects are and how that works. 154 00:10:27,540 --> 00:10:33,630 ‫But basically the red line that we use is this bright line here where we just enter a string and if 155 00:10:33,630 --> 00:10:39,000 ‫you want to know more about it, you can just click on it and you will see that it will return a void 156 00:10:39,000 --> 00:10:39,900 ‫or return nothing. 157 00:10:39,900 --> 00:10:45,150 ‫So it writes a specific string value followed by the current line terminated to the standard output 158 00:10:45,150 --> 00:10:45,810 ‫string. 159 00:10:46,050 --> 00:10:46,650 ‫All right. 160 00:10:46,650 --> 00:10:49,740 ‫But as I said, we will look a lot more into that later on. 161 00:10:49,740 --> 00:10:51,090 ‫It will make a lot more sense. 162 00:10:51,090 --> 00:10:56,040 ‫So don't worry if you didn't understand every single part of it and don't worry about memorizing all 163 00:10:56,040 --> 00:10:59,310 ‫of that, we will just use those methods quite extensively. 164 00:10:59,310 --> 00:11:01,500 ‫And and that will become very natural later on. 165 00:11:01,950 --> 00:11:02,370 ‫All right. 166 00:11:02,370 --> 00:11:03,600 ‫So see you in the next video.