Home >Backend Development >C#.Net Tutorial >What is the basic structure of a C# program?
Let us first look at a C# sample program-
using System; namespace DemoApplication { class HelloWorld { static void Main(string[] args) { Console.WriteLine("Welcome!"); Console.ReadKey(); } } }
Now let us see what the above program contains-
The first line of the program using System; - The using keyword is used to include the system namespace in the program. A program usually has multiple using statements.
The next line is the namespace declaration. A namespace is a collection of classes. The DemoApplication namespace contains the class HelloWorld.
The next line has a class declaration, class HelloWorld contains the data and method definitions used by your program. Classes usually contain multiple methods. Methods define the behavior of a class. However, the HelloWorld class has only one method Main.
The next line defines the Main method, which is the entry point program for all C#. The Main method describes what the class does when executed.
The Main method uses the statement Console.WriteLine("Welcome!"); to specify its behavior. >
WriteLine is a method of the Console class defined in the System namespace. This statement causes the message "Welcome!"
The last line Console.ReadKey(); is for VS.NET users. This causes the program to wait for key presses and prevents the screen from quickly running and closing when launching the program from Visual Studio .NET.
The above is the detailed content of What is the basic structure of a C# program?. For more information, please follow other related articles on the PHP Chinese website!