With these essential building blocks covered,
let's return to Visual Studio and apply these already.
So let us investigate some of the C# basic syntax rules,
and I'm going to do that in a new project.
So we'll create a new project, we already know what a project is,
of course, we'll select the Console application again,
and this time I'm going to call the application BethanysPieShopHRM.
That is going to be the name of the application that we'll
be working on throughout this course.
And of course,
we'll select .NET 6 as the version of .NET that
we'll build this application with.
When we write Console.WriteLine, we need to pay attention for a few things.
When I want to write something to the console,
it needs to go between a pair of brackets.
Of course, when you open a bracket, you will also need to close it.
When I write between the brackets, a string that I want to write to my console,
I need to put it between a set of quotes.
This is a C# statement, and it needs to be ended with a semicolon.
The semicolon is typically put right behind it,
but I can, in fact, place it wherever I want.
We can add spaces here, we can add tabs here,
it doesn't really matter, we can even put a new line here,
and this will still be okay.
New lines and spaces don't have any influence when writing C# code.
I think though that it is much more readable if we put the
semicolon right behind the closing bracket here.
Now if I, for example, forget to close the pair of quotes here,
automatically that bracket and that semicolon become part of that text,
and therefore,
Visual Studio is now flagging an error because that
statement is not ended in a real semicolon because the
semicolon is not part of the string.
Now I also see that the colors used by Visual Studio will
help us to identify problems in our code.
I've added here another line,
which is very similar to the one we just had at the top.
Now let us start accepting some input, and for that,
we'll need to create a variable.
I will create a variable again like we did in the previous module,
but I'll do it here again.
So I'll accept text input from the console,
and I capture that in this variable called name.
It is of type string, it is text, but we'll talk about types very soon.
When creating identifiers, there are a couple of rules that we need to obey.
We can, for example, do the following.
The identifier can contain letters, numeric values,
and underscores, so this is a valid identifier.
So is this one because it contains an underscore, and that's valid as well.
Our identifiers need to be unique, but since C# is case sensitive,
this is also valid because name2 and name_2 are different identifiers,
so both can coexist in our C# code.
Now one other rule is the following.
We cannot create a variable where the identifier starts with a number.
This will be flagged by Visual Studio.
We get a red squiggly saying that this is not going to work.
Now since it's not going to compile, I can actually comment it out.
Before this line, I can go and I can put two slashes in front of it.
This will make the line green in Visual Studio,
again the colors are helping us, and this is now harmless.
It is not going to be compiled anymore,
it is now just text that is just comment in our code.
If you want,
you can also put a number of lines in comment and then you can go
here to this Comment out selected all lines button,
and then you will comment out all the lines you have selected.
That is also accessible via a shortcut called Ctrl+K/C.
This will comment out multiple lines in one go.
By using Ctrl+K/Ctrl+U, you will uncomment multiple lines in one go.
Typically, comments are used to indicate what the code is going to be doing.
This would be a valid comment explaining what the next line will do.
Here you see a multiline comment which is surrounded with a slash and
an asterisk and closed with an asterisk and a slash. All the text between these two sets is automatically seen as comment.