C# Distinguishes between Uppercase and Lowercase

The C# language distinguishes between uppercase and lowercase letters so we should use the correct casing when we write C# code. In the example above we used some keywords like class, static, void and the names of some of the system classes and objects, such as System. Console.

Main Formatting Rules

If we want our code to be correctly formatted, we must follow several important rules regarding indentation:

·         Methods are indented inside the definition of the class (move to the right by one or more [Tab] characters);

·         Method contents are indented inside the definition of the method;

·         The opening curly bracket { must be on its own line and placed exactly under the method or class it refers to;

·         The closing curly bracket } must be on its own line, placed exactly vertically under the respective opening bracket (with the same indentation);

·         All class names must start with a capital letter;

·         Variable names must begin with a lower-case letter;

·         Method names must start with a capital letter;

Code indentation follows a very simple rule: when some piece of code is logically inside another piece of code, it is indented (moved) on the right with a single [Tab]. For example if a method is defined inside a class, it is indented (moved to the right). In the same way if a method body is inside a method, it is indented. To simplify this, we can assume that when we have the character “{“, all the code after it until its closing “}” should be indented on the right.

 

 

File Names Correspond to Class Names

Every C# program consists of one or several class definitions. It is accepted that each class is defined in a separate file with a name corresponding to the class name and a .cs extension. When these requirements are not met, the program will still work but navigating the code will be difficult. In our example, the class is named HelloCSharp, as