C# Hello World program
using System;
namespace HelloWorldApplication {
class HelloWorld {
static void Main(string[] args) {
/* my first program in C# */
Console.WriteLine("Hello World");
Console.ReadKey();
}
}
}
- The using keyword is used in the first line of the program to include the System namespace in the program. There are usually several using statements in a program.
- The namespace declaration is on the next line. A collection of classes is referred to as a namespace. The HelloWorld class is found in the HelloWorldApplication namespace.
- The class HelloWorld, which holds the data and function definitions your program utilizes, is declared next. Multiple methods are common in classes. The class's behavior is defined by its methods. On the other hand, the HelloWorld class contains one method, Main.
- The Main method, the starting point for all C# programs, is defined following. When the class is executed, the Main method specifies what the class does.
- The compiler ignores the next line /*...*/, which adds comments to the program.
- The Console statement defines the behavior of the Main method.
- The Console class in the System namespace has a method called WriteLine. The message "Hello, World!" appears on the screen due to this sentence.
- For VS.NET users, the last line Console.ReadKey(); is used. When the program is launched from Visual Studio.NET, this makes the program wait for a keypress and stops the screen from running and closing rapidly.