May 11, 2021 C#
In this section, we'll learn the structure of the programming language, and in order for everyone to have a better understanding of the structure of the C#program, we'll first demonstrate a minimal, simplest of the structure of the C#program as a reference for the next chapter.
A C#program consists mainly of the following sections:
Let's look at a simple code that prints "Hello World":
using System;
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
/* 我的第一个 C# 程序*/
Console.WriteLine("Hello World");
Console.ReadKey();
}
}
}
When the above code is compiled and executed, it produces the following results:
Hello World
Let's take a look at the various parts of the program above:
WriteLine is a method that defines the Console class in the System namespace. The statement displays the message "Hello, World!" on the screen.
The following points are worth noting:
If you'Studio.Net visual to compile and execute a C# program, follow these steps:
You can also use the command line instead of the Visual Studio IDE to compile the program:
If you are prompted not to recognize the csc command, configure the environment variable (Window10) as follows:
Right-click the Computer icon on the desktop and click on "Properties" - "Advanced System Settings" - "Environment Variables" - "System Variables" in the pop-up menu, find the variable Path, add the path "C:?Windows\Microsoft.NET\Framework\v2.0.50727" (note that multiple paths are separated by ;), and other versions of Windows are available later).