C # Namespace and assembly _c# tutorial

Source: Internet
Author: User
Use the full name of the class:

System.Text.StringBuilder sb = new System.Text.StringBuilder ();

The above writing is cumbersome, using a using statement to introduce the namespace:

Using System.Text;
StringBuilder sb = new StringBuilder ();
For the compiler, the namespace is to attach some separator symbols to a type, making the name more unique.
C # 's using directives are optional and can be replaced with the full name of the type, which instructs the compiler to
Each type attaches a different prefix, determining the full name of the match.
The CLR does not know anything about namespaces, and the CLR knows the full name of the class to lock down which assembly it is defined in, and then load the assembly and manipulate it.
C # 's using directives also support another form that allows you to define aliases for a type or namespace:

using int = System.Int32;
int i = 0;
Namespace and assembly relationships:

An assembly is a file of the implementation type, which is generated after compilation.

Namespaces are logical groupings of types.

Types in the same namespace can be defined in different assemblies.

The same assembly may also contain multiple namespaces to group types.

The C # compiler may be more concerned with namespaces, and it needs to determine the full name of the class and then give it to the CLR.

The CLR only cares about the assembly, and the corresponding assembly is loaded with the full name of the class.

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.