What is the basic structure of a C# program?

WBOY
Release: 2023-09-27 16:33:02
forward
1464 people have browsed it

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();
      }
   }
}
Copy after login

Now let us see what the above program contains-

using

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.

Namespace declaration

The next line is the namespace declaration. A namespace is a collection of classes. The DemoApplication namespace contains the class HelloWorld.

Class Declaration

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.

Main method

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.

Console.WriteLine

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!"

Console.ReadKey()

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template