In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the program structure of C#". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the program structure of C#"?
Before we learn the basic building blocks of the C # programming language, let's take a look at the smallest program structure of C #.
C# Hello World instance
A C# program mainly includes the following parts:
Namespace declaration (Namespace declaration)
A class
Class method
Class attribute
A Main method
Statement (Statements) & expression (Expressions)
Annotation
The suffix of the C # file is .cs.
Here is to create a test.cs file that contains simple code that prints out "Hello World":
Test.cs file code:
Using System
Namespace HelloWorldApplication
{
Class HelloWorld
{
Static void Main (string [] args)
{
/ * my first C# program * /
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 above program:
The first line of the program's using System;-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 contains a series of classes. The HelloWorldApplication namespace contains the class HelloWorld.
The next line is the class declaration. The class HelloWorld contains the data and method declarations used by the program. Classes generally contain multiple methods. Method defines the behavior of the class. In this case, the HelloWorld class has only one Main method.
The next line defines the Main method, which is the entry point for all C # programs. The Main method specifies what the class will do when it is executed.
The next line / *. / will be ignored by the compiler, and it will add additional comments to the program.
The Main method specifies its behavior through the statement Console.WriteLine ("Hello World");.
WriteLine is a method of a Console class defined in the System namespace. The statement displays the message "Hello World" on the screen.
The last line, Console.ReadKey ();, is for VS.NET users. This causes the program to wait for a keystroke action to prevent the screen from running and closing quickly when the program starts from Visual Studio .NET.
The following points are worth noting:
C # is case sensitive.
All statements and expressions must end with a semicolon (;).
Execution of the program starts with the Main method.
Unlike Java, the file name can be different from the name of the class.
At this point, I believe you have a deeper understanding of "what is the program structure of C#". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.