C # Solutions, engineering, namespaces, the meaning and nature of the main function.

Source: Internet
Author: User

The solution is unique, and there is only one in one program.

The top one is the solution. There are a lot of projects under the re-solution, such as the default ConsoleApplication1, which is now a project.

We can add a lot of projects to the solution.

The diagram of the console program, form programs, class libraries and so on are engineering, can be added in the solution, in fact, the project is engineering.

There are a lot of source files in the project (. CS extension), there are many other configuration files (such as app. config).

Now you might ask. Since there are so many projects, which one will run when the program starts? You can actually set up a project for your startup project.

The following explains the namespace.

Namespaces are like a folder that contains many classes, delegates, interfaces, and so on.

C # organizes all classes by tree, and the top level is the namespace.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Remoting.Messaging;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.IO;//Microsoft directly gives the namespace. namespaceConsoleApplication1//your own namespace{    classProgram {Static voidMain (string[] args) {        }

We can modify it at will after namespace. Because it is just a namespace that is easy to organize and invoke, it has no effect on the program itself.

For example, we can put the above

Namespace ConsoleApplication1 instead
Namespace AAA
Classes that are written under different namespaces must use a using namespace reference when they are called across namespaces, otherwise they will not be recognized.
The following discussion of the program class does not really mean that we can modify it at will.
We can change the code to
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Remoting.Messaging;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.IO;//Microsoft directly gives the namespace. namespaceAaa//your own namespace{    classHi {Static voidMain (string[] args) {        }

It's not wrong.

The main function is special, he is the entry of all programs can be arbitrarily modified, but you can also define the main function in different classes.

However, in order for the program to actually execute, you must specify the startup object, which is set in the properties of the project.

The point is the key to see how you set, a lot of things are not unique.

In addition, all methods and variables in C # cannot be separated from the class.

All code relies on namespaces for organization and invocation, and in the same solution, you can directly use the using to invoke the namespace of the same schema.

One of the more important things is that you can create a class library---write the important class--build in this project file will produce a DLL file that can be copied to other solutions to reference,

C # Solutions, engineering, namespaces, the meaning and nature of the main function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.