C-SHARP - 2.4 Type and constant exercise

Hello everyone and welcome to this new video. In this video, I will give you a little exercise to do to put into practice the theory we saw just before. The exercise is as follows: I want you to show me in console a person's personal information, which will be kept in variables. Basically, here is the result I expect from you. You must respect this structure After the data you can put what you want. However, I want you to use the different types we saw in the previous video. For this "Your first name" you know that it is data that does not change and that it is a chain so it's up to you to guess. Then the age of the person is a number that changes over time The balance of his bank account It is a decimal number. It's up to you to guess the type you're going to use. Review the previous video if you need to help. In any case, it's up to you to play! Pause the video, and we'll do right after for the correction. On your marks! Ready! Code! We are now coming together for the correction of the exercise, I hope you have succeeded. Otherwise, pay attention to the correction. Let's go! So at first you had to display a person's first and last name. I'm going to close the exit window. And we know that first and last names are data that will not change in our program. So here who says data that does not change, we think directly of constants. But also since they are strings it will be a string type So we will create a "name" constant by typing const of type string that we will call name Then we put a = and the value you want Me I will take the example I showed you previous. I put "" "Oubelaid" And I don't forget them; Then I go to the line I create a new constant for the first name So I type string type Const Then I'll call it first name. = In quotation marks. "Jibril" And don't forget them; Here we're not going to display them right away I'll first create all my variables and then we'll display them. So let's go to the line. And as you see Here you had to display an age. So a number And age changes with time so here it won't be a constant but a variable of an int type since it's a number I could have used a byte or shorts it's quite possible because the age will always be between 0 and 255. Then, in general, we often use an int for numbers. so as not to have problems in memory. If you have chosen the byte or shorts, it is also correct. Don't worry To return to our variable age so you must enter its type. type int Then the name of the variable. age for example then = And the age you wanted to give it, for my part 17. Don't forget them; And to finish the balance of his account. Here we have a decimal number that says decimal number, says real number So we have: float, double, and decimal. Here you can choose one of the three it remains correct. However, you remember that the double and decimal took up more space in memory. 8 bytes for the double and 16 for the decimal. Therefore, here we don't need to use so much space in memory for a simple balance, you see? As a developer, we must make sure to create optimized programs, as light as possible for the machine and that consumes little energy. For reasons of speed, cost and the environment? An unoptimized program will cause speed concerns, consume more etc. ... So it is important for your future as a developer to worry about all these constraints. So to return to our balance, you had to create a float variable then you could give it as the name balance = a decimal number so 3045.5 Here on the other hand it is not a comma that must put but a point And don't forget them; at the end But you see I have an error, you remember that I had listed in the previous video a small Especially for the float and decimal. Indeed, if we do not tell the compiler if it is a float or a decimal, it processes duplicate by default. Except that you can't put a duplicate in a float or decimal type. So you just had to add an F just after the last digit of the number If you had chosen the float type it was an f and m if you had chosen the decimal type. For the double there was nothing to put on. Now that we have created all our variables we will display them For this, we go to the line you type the shortcut of the Console.WriteLine() so cw You make a tab Then between parentheses you type " " "Your name: " + and the name variable And don't forget them: at the end Then I will copy and paste this line several times to go faster. And now I just have to change the values, here I'm going to put first name. And here is the first name variable. Then here. age And there the age variable. And to finish here, balance. And there is the balance. I can now launch the program. And you see that we have the expected result I hope in any case that you have succeeded and that this video has you more. I'll see you next time in a new video.