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.
Be careful when writing! The same thing, written in upper-case, lower-case or a mix of both, means different things in C#. Writing Class is different from class and System.Console is different from SYSTEM.CONSOLE.
This rule applies to all elements of your program: keywords, names of variables, class names etc.
The Program Code Must Be Correctly Formatted
Formatting is adding characters such as spaces, tabs and new lines, which are insignificant to the compiler and they give the code a logical structure and make it easier to read. Let’s for example take a look at our first program (the short version of the Main() method):
class HelloCSharp
{
static void Main()
{
System.Console.WriteLine("Hello C#!");
}
}
The program contains seven lines of code and some of them are indented more than others. All of that can be written without tabs as well, like so:
class HelloCSharp
{
static void Main()
{
System.Console.WriteLine("Hello C#!");
}
}
Or on the same line:
class HelloCSharp{static void Main(){System.Console.WriteLine( "Hello C#!");}}
Or even like this:
78 Fundamentals of Computer Programming with C#
class
HelloCSharp
{
static void Main()
{ System .
Console.WriteLine("Hello C#!") ;} }
The examples above will compile and run exactly like the formatted code but they are more difficult to read and understand, and therefore difficult to modify and maintain.
Never let your programs contain unformatted code! That severely reduces program readability and leads to difficulties for later modifications of the code.
Main
0 Comments