C# Syntax (incl Comments)

Let’s start from that project which we have created in our previous lecture

  • using :  Basically, with this keyword, we add a different namespace in our project. For the usage for their classes. In the case of C#, the System namespace is where many useful things are described. One of these useful things given C# is that the Console class can let me write things which can appear on the screen ahead of the user to this as Console I even have to inform the compiler I'm using the System namespace. The means that if I ask something by a specific name the compiler will look in the System to ascertain if there's anything matching that name
  • Namespace :  A namespace is a collection of classes and another namespace. We are using the namespace to organize our project.
  • { } : These brackets (curly brackets) use to mark the beginning and end of the code block.
  • Class : Class is the container of method and other data.
  • Main : The main method is the entry point of the application.
  • Console: A class from the System namespace
  • WriteLine/Write : A method in the console class that is used to print or display the value.
  • Static : This keyword makes sure that the function which follows is usually present
  • Void : A void is nothing. In programming terms, the void keyword means the method we are about to describe doesn't return anything of interest to us. The method will just do a job and then finish.

Difference between writeline and write

The difference between writeline and write is that writeline print new line every time but write just print on the same line.

A big part of a well-written program in the comments that the programmer puts there. A program without comments is a bit like an airplane that has an autopilot but no windows. there is a chance that it might take you to the proper place, but it'll be very hard to inform where it's going from the inside.

Comments

  • Comments in C# are the human-readable text for detailing what this code is doing
  • In a high-level English statement, you are describing what your program is going to do.

Block Comments

When the C# compiler sees the "/*" sequence which means the start of a comment it says to itself: I will ignore everything following until I see a */ which closes the comment.

As an example:

/* This program works out glass and wood required for a double glazing salesman. */

Be generous together with your comments. they help to make your program much easier to understand. you will be very surprised to find that you quickly forget how you got your program to work. you can also use comments to keep people informed of the particular version of the program, when it was last modified and why, and the name of the programmer who wrote it – even if it was you.

If you're using an editor that supports syntax highlighting, you will find that comments are usually displayed in green.

Line Comments

Another form of comment makes use of the // sequence. This marks the start of a comment which extends to the top of that particular line of code. it is useful for putting a quick note on the top of a statement:

position = position + 1; // move on to the next customer