In this video we're going to be creating our first console application.
So let's get started right away.
Bring up Visual Studio and then go to create a new project and then we can narrow it down to see a console
app so maybe you did that's already maybe you didn't.
That's fine but you can always just go to see sharp windows and then select console in this third one.
Or you can just search console and then it will narrow it down for you know we're going to start off
with a dot net core console up this time so select console update on it core fleet next.
And then we name it differently this time.
So we have a project name somewhere to call this one.
Hello world.
That's the name of the project.
Well then I'm went to have multiple projects underneath my solution so I don't want my solution to be
called Hello World.
And then I'd want to have multiple projects with other names so naming is very important.
It helps you to identify exactly what you're seeing.
And you know it just makes life easier for too much.
So I'm going to call this entire solution console programming because once again we're going to have
this solution with a bunch of projects geared towards us learning console programming.
So the solution name once again is console programming.
But the project that we're creating right now is called Hello world.
So I am just going to click Create and allow Visual Studio to do its thing.
No one Visual Studio launches our project you're going to see something very very very unique.
You notice that it's already launched our program that we just said we're going to write it is printing
hello world to the console.
No I just want to before we look at the code I just want to point out that a solution is going to solution
Explorer is going to have a slightly different look say if you use the dot net framework.
I know you're using alternate core then the files the label may look slightly different but ultimately
it's the same set of concepts you have your program dot see this file and that is the one that comes
open when Visual Studio launches and we see that we have a class called program and it has a function
called mean and so mean gets called once your application launches whatever is inside of our main function
is what gets fired.
All right.
If you expand dependencies then you'll see they have dependencies frameworks and then basically any
libraries that you may want.
So sometimes you want to do a particular thing and somebody has what they call a library that they've
done it in already.
You can actually include them and then use the library but that's for later on.
I'm just giving you an appreciation of what you're looking at right.
No.
So no we'd need to see exactly what happened.
So once again our code is console dot right line and then we open the briefs and then we have quotation
marks.
That's a Hello World Class quotation marks floors brace and then semicolon.
So I'm going to explain what each token means.
But I just want us to see how this works first.
So once again to execute I'm just going to go and click the Start button or we can just press f five
on our keyboard we let it build all right.
And then we get our consoles so our console once again looks something like a command prompt.
If you ever had to use Come on problems you know that little black box wary of the type and run commands.
Well that's what a console program is.
So we're seeing here Microsoft studio Microsoft Visual Studio sorry Debo console.
And then we see that it's printing hello world.
And then it gives us some data all where it's printing it from.
And you know it will automatically close when debugging and press any key to close this window so I
can just press enter and that window will disappear and we're right back where we started.
Now let me take the time to explain exactly what is being written here.
Notice one that visual studio kind of tries to give you color coding you see that it's quite colorful.
You have blue takes it wide takes.
You have.
I don't know what color that is any kind of yellowish looking text your code hinting sorry your color
coding might be different based on the theme that you're using.
So if you're in the light theme or in the blue theme then you're color coding may not be the same as
I have it here but just have an appreciation for what gets color coded.
So we have namespace namespace refers to the pretty much the project.
And then by extension the folder in the project.
So if we had a folder in this project with a class file in there then the namespace would be Hello World
dot dot folder name.
So program six is directly inside of our project.
So the namespace is just hello world.
All right.
We have a class.
So our class is a collection of what we call properties and functions but I'm not going to teach classes
just yet.
But our first and major class is class program because that's the first thing that gets fired when a
consulate up is going to run.
And then inside of program we have static void Main and it takes some args.
Right.
So I don't want to get into too much detail about what the args means but just know that if you're going
to modify anything in this file do not modify the class name and do not modify the main function you
can do any bit of changes you want inside of here inside off the main function and we know where we're
inside because you see the open brace and the closed brace.
I notice it's kind of hinting where the brace closes it's trying to do all of that for you to help you
not make certain mistakes or at least find them quickly.
So the namespace has an open brace and a closed brace and inside of those we have the class and that
opens and closes and then instead of the function.
So this is a function in all functions because you have the open brace and the floors brace instead
of the main function.
Well you have currently braces a I have breeze.
So our power indices.
So sometimes I use them interchangeably but I just realized that I use them slightly interchangeably.
So we have curly braces and then we have the regular braces are the parentheses.
All right.
So we know functions because they have parentheses and they may or may not have values inside of the
open and closed.
So in this case mean has values.
And we don't have to trouble that.
And then after declaring our function we have open curly brace and close curly brace.
Then we define what this function should do inside of those braces.
In this case we said do do a print.
So the console that says hello world.
So notice we have class and we have a function.
Notice the color coding program is a class and domain is a function.
I'm pointing that out because if you look at the color coding realize that console is a class the word
console is a class and right.
Line is a function and we know functions because one the color coding may look the same.
And if it doesn't for you that's fine.
But we need to know our function in any C sharp code that you're looking at is to see that it has parentheses
afterwards whether or not it has values in there.
That's a different story.
So I could actually see bright line and then that would just be quiet.
OK.
So right.
Line is a function because it says the open and close parentheses.
And if I wanted to define the text that's I want to return to the console.
So literally seeing this is the console call the console and write the line that I am putting inside
of the open and close braces or parentheses.
So then I'm going to put my Kindle world.
And that is how our program came.
All right.
No I want to annotate this code because you know where I'm starting C Sharp I want to look at it tomorrow
and remember that all oh that's what was happening here so I can just put in what we call a comment
by using slush.
All right.
And then I can type anything I want someone to see.
Printing to console screen.
So that's our print to the console screen.
You can use the slash slash.
Do.
If you wanted to write a paragraph maybe you wanted to be a bit more explicit about what everything
is.
Then you can use the slash then an asterisk.
And then in between those you can have as many lines as you need.
All right.
Just writing some random stuff and then you just make sure that you close it with the asterisk and the
slash.
All right.
No.
You'll notice that when when I'm showing you guys how to do things I'm always open and close at the
same time.
And that's avoid making the mistake of forgetting to close it.
So sometimes we get carried away and we start writing code and we open the codebase and write and write
and write and we don't close occurring libraries.
And then later all we're getting errors that we're wondering why are we getting errors because everything
looks OK.
So I'm just going to show you what I mean by getting arrows and whole visual studio goes about showing
you that you have arrows.
So if I forget to close a brace and maybe I forget the part indices I notice every line ends a semicolon.
But when we have multiple lines up pay more attention to that.
So when you see that some lines start appearing so any average lines in visual do that's never a good
thing.
They can appear because the syntax is incorrect.
So the red line here is saying that hey you know something is wrong.
I'm not entirely sure what but something is wrong somewhere.
I can always go to the error list and then it will kind of tell me that there is an expected talk in
somewhere.
So if I double click that it will kind of bring me to the line that the arrow is that.
But this is not quite where the arrow is.
However I can debug this and see that OK when I click this close one it's matching.
So this goes one which is inaccurate because I have a curly brace here.
I know when I click this one it's matching to this.
So that means I created braces missing somewhere so I can just press enter and then I can put the curly
brace and notice so everything realign.
So visas to do it actually realign everything because then it realizes OK so you're closing this one
no.
So let me just realign and reinvent everything so you can see exactly where your code starts and stops
indentation is very important it makes the code look clean and readable two more things.
Notice that we have a little asterisk beside the program name or the code file name rather and that
asterisk is just an indicator that this file has been modified so you can always just know which file
has not been saved.
When you look at the file name the tab and you see that asterisk.
You can always save it save all if you have multiple files or if you've made modifications and you click
run then it will automatically see automatically recompile and then allow you to proceed.
So if I have some legal characters here.
All right.
And we just looked at arrows I see red lines maybe I thought I wrote the code properly but Visual Studio
sees it as illegal then it's going to one allow me to hover over it and give me potential fixes.
So I went to dropdown this.
This is the light bulb and it's going to suggest some things to me know the suggestions are usually
like grasping at straws because there are arrows that business to do knows about that maybe you declared
something improperly then it will say Oh I see that you declare this but you didn't do this step do
you want me to do it for you then you say sure and it does it for you.
However in this situation this is random takes the results to do doesn't know what to do.
So no none of these suggestions will really fix the problem.
Another thing to note is that if I tried to execute well there are arrows it will do the build and then
it will tell me that there were arrows.
Do you want to run the last successful build.
I tend to always click No because it doesn't make sense I run the last successful belief I'm trying
to build my current bits of code so you click No.
And then it will kind of show you the arrow pin telling you that you have some arrows there's a semicolon
expected.
All right.
So at least it said to me that if you're going to write code directed properly but then the arrow list
is still telling me that there are things missing something here that they cannot cope with.
So if I remove this or I can just comment it out make it you know or let me use the other comment so
I just come into to.
So that's one way to comment and this is another way to comment and then order is restored.
And if you look down there they're a little visual cues along the way to tell you how many issues you
have there too.
I mean no issues phoned.
No that I fixed my arrows I'm just going to run my console application once more and then we see that
we have our hello world printing to the screen once again so I can press enter if I ever wanted to find
this project and find the files.
You know I have the project I have the solution of the project but I don't want to open it in visual
studio maybe I want to put it on a flash drive.
I want to physically move it to some storage device so that I can use it on another machine.
Then we can easily just the right click solution and then you'll see open file in file explorer.
So when I do that it launches my file explorer showing me this file and I'm going to see if I can zoom
in a bit so you can see what the files look like better.
So then this is the most timeless logo in the Dutton community.
This is the logo that represents the solution file.
Once you double click the solution file it will launch Visual Studio and basically launch the projects
that are inside of that solution.
So that's one quick way to get back to your project that you're working on.
You just find the physical location where you started.
You double click the solution file and then it will launch Visual Studio with all of the code that you've
written.
Notice hello world is in its own folder.
And that's because it is a project.
So each project will get put in its own folder and all of them will be in one folder together with the
name of the solution.
So the solution was console programming.
It created a folder.
Then he gave me a solution file notice the extension.
That s a n and then for each project it gives me a folder with that name.
So like I said the naming is very important.
So those names are manifesting outside of Visual Studio.
And then if I look inside this folder and want to see a bunch of little of the files.
Well we'll get back to those files on what they're really about.
That's it for building a Hello World console application and understanding Visual Studio a bit more.
Next we look at how we write a program to receive data from a user and print something back to the screen.