C sharp - C# Syntax
C# Syntax
In the previous chapter, we created a C# file called Program.cs, and we used the following code to print "Hello World" to the screen:
using System;
class Program
namespace helloworld
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
Line 1: using System
means that we can use classes from the System
namespace.
Line 2: A blank line. C# ignores white space. However, multiple lines makes the code more readable.
Line 3: namespace
is used to organize your code, and it is a container for classes and other namespaces.
Line 4: The curly braces {}
marks the beginning and the end of a block of code.
Line 5: class
is a container for data and methods, which brings functionality to your program. Every line of code that runs in C# must be inside a class. In our example, we named the class Program