25/08/2022
Lesson One (unit 3)
What is a programming language?
The instructions we write in a programming language is called "source code", or just "code".
At this point, the code can be updated and changed by a software developer, but the computer can't understand the code. It first must be compiled into a format that the computer can understand.
What is compilation?
A special program called a compiler converts our source code into a different format that is executable by the computer's CPU. When run the command dotnet run, the code we wrote was first compiled, then executed.
Why do we need to compile our code?
Even though most programming languages seem cryptic at first, they can be more easily understood by humans than the computer's preferred language, which is expressed by turning thousands or millions of tiny switches either on or off. Compilers bridge these two worlds by translating our human-readable instructions into a computer-understandable set of instructions.
What is syntax?
The syntax of a programming language includes the keywords, the operators (those special keyboard characters like the semicolon or parenthesis), and other grammar rules that the compiler enforces. The lines of code you typed followed about a dozen different syntax rules and used at least four different operators. There's much to learn, but fortunately each concept is simple. Don't give up! You can learn it!
When you entered code, you may have noticed subtle changes to the color of different words and symbols. Syntax highlighting is a helpful feature that you'll begin to use to easily spot mistakes in your code that don't conform to the syntax rules of C #. In fact, a similar (and even more robust) version of this feature is available in Visual Studio Code and the full Visual Studio IDE.
How did our code work?
Let's focus on the following line of code we wrote. When we ran our code, we saw that the message Hello World! was printed to the output pane. When the phrase is surrounded by double-quotation marks in our C # code, it's called a literal string. In other words, we literally wanted the characters H, e, l, l, o, and so on, sent to the output. We'll learn more about literal strings later.
The WriteLine() part is called a method. We can always spot a method because it has a set of parenthesis after it. Each method has one job. The WriteLine() method's job is to write a line of data to the output window. The data that's printed is sent in between the opening and closing parenthesis as an input parameter. Some methods need input parameters, others don't. But if we want to invoke a method we must always use the parenthesis after the method's name. The parentheses are known as the method invocation operator. We'll learn more about calling methods.
Note: Console.WriteLine() and Console.Write() methods produces the same output.
The Console part is called a class. Classes "own" methods, or perhaps a better way to say it is that methods live inside of a class. To visit the method, we must know which class it's in. For now, think of a class as a way to store and organize all of the methods that do similar things. In this case, all of the methods that operate on our Output pane are defined inside of the Console class.
Note: C # is a case-sensitive language, meaning that the C # compiler considers the words console and Console as different as the words cat and dog.
There is also a dot, or period, that separates the class name Console and the method name WriteLine(). The period is the member access operator. In other words, the dot is how we "navigate" from the class to one of its methods.
Finally, the semi-colon is the end of statement operator. A statement is a complete instruction in C #. The semi-colon tells the compiler that we're finished entering the command.
Understand the flow of ex*****on
Also, it's important to understand the flow of ex*****on. In other words, our code instructions were executed in order, one line at a time, until there were no more instructions to execute. Some instructions will require the CPU to wait before it can continue. Other instructions can be used to change the flow of ex*****on. we'll learn about these special situations as we learn more C # syntax and methods in the .NET Class Library.