In this video we're going to be creating our projects that will receive user input and print some outputs.
I'm starting from our folder where our project was created because maybe you shut down the machine you
went to have dinner.
It's been days since you were last in Visual Studio and so I just want to show you how you can relaunch
your project from the file system and you know not to have to go into Visual Studio and source it so
I can just go back to the file system find the solution and double click.
That will launch results to you and that will relaunch our project our solution with our project and
everything that we were doing.
So every time you go ahead and you correct code and you save and you relaunch a solution it may relaunch
with all of the tabs yard open or the court files and all the projects and everything that you know
let's go about putting a new project inside this solution so that we can test or write a new program.
So this was our hello world program notice at a comment here at some static takes or some random text
that was giving problems that just come into default.
But that's it for the whole world so let's move on to a new one.
Someone to write the solution note not the project.
This is the project I'm right clicking the solution so or I notice that it's really just a config file
right.
So I'm right clicking the solution and with the click add and then I'm going to see new project then
it brings back this menu that we should be familiar with this dialog box that we should be familiar
with asking Okay what kind of project do you want this time.
So I'm going to select once again console up dot net core click next and then this time I want the project
need to be input output so input outputs lots of spelling errors.
So you want to make sure that you write it properly right.
Naming is important.
And then I click Create and then I get a brand new code.
So notice it's kind of standard to come with hello world hello world is probably the first programming
phrase that most people will ever learn when they're learning a new language how to print Hello World
to the screen but that being said I just wanted to take some time to appreciate what is happening here.
So notice I have a new program that seems file I still have my existing one and then so as not to make
the mistake and let's assume that they were both identical they were both very new.
Both of them had the same code in it.
How do I know which one belongs to which project.
So each time I have a console application or project you're going to get a program that's yes file and
it's going to come with a main function and let's just say it's standard for it to say hello or that
means we've seen that with the dot net core template we can use this dropdown list to look at which
project it is in.
So this program that ceasefire belongs to the hello world project.
If I go to the next one you see that it belongs to the input output project.
If I close them both and just does this file.
That's a project file.
And I have no files open then from the solution Explorer I can specifically go to which project I want
and then select the program gutsiest file.
All right.
So that's all you can manage multiple projects and appreciate where what file is coming from so you
don't make mistakes.
Goes well you don't want to be writing input output stuff instead of hello world program dot.
Yes.
And then when you're running you're wondering why is your code not working or why isn't it detecting
the code that you wrote.
And that's just because you wrote it's in the wrong program.
That's yes.
So you want to be very careful and very attentive.
And as you build more and more applications even more advanced applications you're going to have multiple
projects we just want to be very careful unsure where each file is.
Now let's get started.
I did say that we wanted to write something to get user input and then print back to the screen so let
me just remove.
Hello world.
So we're going to be learning a few things here.
We're going to be learning about one variables to hold to prompt for inputs received from the user.
And then three how to print it back to the screen.
So let's get started with variables and I'll just put comment variables.
A variable is like a little container.
All right.
So when we want data from the user we have to create a container and then we use a container to store
the value that the user gave us.
So for instance if I wanted a name then I need a variable and it makes sense to just call its name the
name of my country and therefore somebody whose name is name.
All right.
And then further to that I need to define a type.
So a type means the type of data that I'm expecting.
So if I want somebodies name then that is text because they'll be writing letters.
All right.
So anything that's letters is a text type or a string.
So in C sharp we call text types string when you want text from somebody you need a pocket or that container.
And it needs to be able to store what we call a string or text.
All right.
So let's start off with all we declare a variable.
I will first define the data type so C sharp eyes.
Lots of data types and it's good to know when to use which one.
So I just gave us a case study for the data type string.
So I say string and then I give it the name.
So I want some variable that is called True.
Now it's called name sorry and it is often data type string you would have already noticed that you
have something called string and args earlier.
So that was the data type and args would be your variable name.
So in this case we're making our own variable telling it that.
OK.
Declare a pocket in memory and call it name and it should be able to store anything that is a text.
So I want name.
That's one.
So I'm going to see the clear variables and then you can have multiple variables.
You can have as many variables as you want.
Right.
But then let's just keep it simple so we want name and then I'm going to want to store what the user
is entering into the console in my pocket called names so I need to assign the data being collected
from the console screen inside of me.
So whenever I want to store data inside of that country you know we see a continued name or variable
name.
So this is name is equal to and then if I'm receiving input I'm going to call my console.
So we get this glass console or remember that when we were printing the screen we had a console as a
class name.
So console once again and then I said dot and then this is all called intelligence where it's telling
me all of the potential things I can do with my console class.
So the thing I want to do this time last time we were writing a line.
So if you scroll or use your right line and you see right but this time I want to read lines so you'll
see that they have an option that is read line so I can double click that.
And then the red line is appearing because it's saying oh yes he read line.
But the context the syntax is not correct and that's because it's a function.
So I need my open and close parentheses.
Then I can use my semicolon.
So I did say I would pay attention to the semicolon.
Every line that you write must end with a semicolon.
There are exceptions but for no let's just follow that rule.
Every line that you write must have a semicolon.
So we'll see the exceptions as we go along and relentlessly is just a matter of practice to get comfortable
with when to use your semicolon.
And when not to know after we've gotten the name then we want to print it back to the screen.
So then I go to the next line.
So this is.
And let me just put the comments as I go along getting value from input or let me see.
Yeah.
Getting on store and getting and storing value from inputs.
All right.
So that's what we're doing in this line.
Then the next line is printing value or values to console screen.
So we've gotten the value and we've stored it.
I know we want to print it back.
So the cool thing is that I can store it.
I can change a value and I can always manipulate whatever is in here before I printed book.
And that's the value of having the the variables.
So no I want to bring it back to screen and we did.
We printed the screen already we did for intel world so we can just follow that same pattern and we
see a console dot.
And remember the print was right.
Line and see intelligence is helping me right line and then it's a function so I need my parentheses
and then they're coordinating me and telling me that OK what do you need inside here is a string value.
So we did put hello world inside quotation marks and that's what a string is it's text like I said.
So whenever one takes we need to open and close quotation marks and then we can type anything we want
any alphanumeric sequence any special characters we want.
Once they're inside of quotation marks see sharp we'll say Well that is static.
I'm not supposed to touch that because that is what my master being you wants me to print.
All right.
So I'm going to remove this and I'm going to so I can put the sentence you know anything I want.
We did see a Hello World last time but what I want to print is not static.
I don't want to determine what I'm printing here because I'm receiving something from the user and I
want to print what the user gave me.
So instead of using my quotation marks and defining you know this is all called static.
All right.
So once it's static it can't be changed again.
So if I type hello world then Hillary will be printed if I type my name manually then obviously I am
bypassing whatever was inserted through the console because anybody can come and use this program put
in that name and this will always just print tor Williams regardless of what values inside name.
So what we want to do is print the value inside of name to the screen and the way that is done is to
actually put the variable names.
So console the right line and then we put in the variable and notice once again we need a string value
but we do have a string variable.
So there are two ways to get the string.
We can use it as static meaning whatever at Whittier will never change until I come back in the code
and change it or I can use a variable of type String.
All right.
So I just declared a variable of type String received some string input from some user and went to print
it back to the screen.
So once again every line ends with a semicolon a CDO studious I mean semicolon is expected.
So I put that there and then I just run no notice that the start still has the hello world.
So if I were only still just going to print Hello world it's just going to execute the hello world program
we have multiple projects and at this point I want to run input output and not hello world.
So what I need to do is change the startup project from hell world to input output.
So I want to right click input output and then select the the option that is set start set.
Start a project so I click that.
And then notice that this is no bull.
So before hello or loss board No this one is bull.
So that's a nice quick way to know which one is a startup project and the notice that contextually the
start button text also changed so I can just click input output.
So my program is started and it's just going to sit there with a blank screen just blinking and waiting.
So what it is doing is waiting on the redesign.
So it already declared name.
You're not going to see a visual cue of the variable being declared.
You're going to forever read line.
It's just going to wait until there is some input followed by an enter key.
So if I put me with a fictitious name Archibald Gordon and then I press enter then it executes A.C.
Archibald Gordon printing about the screen.
No this is not very intuitive because it was just blank you were just waiting what exactly was it waiting
for.
So it's always good to give your user a visual cue to say Please enter your name or something like that
right.
So what I'm going to do is above this line where I am receiving data I'm going to put a console right
line to print to screen the prompt.
So we've got this up prompt so console Dot.
Right.
Line open braces are open parentheses.
And then I want the static text that sees enter your name so I'm saying please I can say Please enter
and name can whatever your prompt is.
So obviously whenever you run a program or you use a program when you're filling out a farm on the Internet
whatever it is you're doing on a computer.
They always give you a visual cue to say this is the data I'm expecting to from you right.
No.
So I'm seeing enter your name and then this line needs to be for the best in the colon.
And then I'm going to wait for you to enter your name.
And then once you have done that I'm going to print your name back to the screen.
So let's try that again all right.
So no it says enter your name because it ran that consular line.
Enter your name.
I know it's waiting for me to enter some value so that again storage inside my variable and then printed
back to screen.
So this time I'm going to use Q Early figure in and then I'm going to press enter and then you notice
it printed.
Kimberly Fagan back to screen.
So no it's still not very intuitive because I don't know which one is which.
Okay I'm looking at a console.
I see Kimberly figure and I just see repeated what what is the repetition for it's not very intuitive.
They always want to put in visual cues to use us so that they know exactly what they're looking at at
each point.
So I'm just going to close this console and then all I'm going to do is putting on the console or Atlanta
or put in more text in this console or line to make sure that contextually you know exactly what you're
looking at.
So what I'm going to do is add another console right line and then this I actually go into the console
right.
So the console dot I have a right line but you also have a right somewhat into our right.
And really the difference between the right and the right line so right is going to see your name is
and then semicolon and then we're writing once again.
So the console the name that was entered.
So let's try that again.
All right so now we see it enter your name.
So OK this time it is Paul Bishop and then we press enter and then we see your name is colon Paul Bishop.
No notice that when we did console right line it automatically went to the next line and waited for
text when we did console a dot right.
It just did it in one line and then whatever as we wanted it stood in that line.
So that's the difference between right and the right line right.
Line automatically it's almost like you type a sentence in Microsoft Word and you press enter and go
to the next line.
That's what right line does for you automatically it just puts the next block of text in the next line
automatically.
However right will not meet that break it will just any other string that is to be printed will just
be printed in the same line onto that line.
You know it's the text wraps.
You know we all should know what word repping is.
So onto the takes the reps are on the screen.
That's all right.
Works.
So that's the difference between console dot right and the console dot right line.
So that's it for input output.
So let's us do a quick review one we learn to declaring variables.
Once again there are many data types that variables can have.
We're just keeping it simple we're just getting started.
So I'm just using string where I collect some text and store inside some variable called name then I
prompt the user for them to enter their name and then once they enter it.
So this is all we get input from the console.
We automatically assign it to our variable having gotten and stored that value from the user.
We then proceed to see your name is.
So we're printing back some static sentence that's giving them a visual cue as to what the data is that
we're printing.
So we're seeing your name is colon.
This takes will never change on this.
I change it in the program but then we dynamically printed whatever name was entered because we printing
by the value in the variable in the next lesson we're going to go through some more data types in C
sharp and look at the requirements between collecting data from the console for these different data
types and printing them back and what conversions need to be done.