. The CTS, CLS, and CLR in net

Source: Internet
Author: User

In learning. NET is inevitably exposed to these three concepts, what are these three things and what is the relationship between them? We may be too much in the process of learning to focus on the CLR because the CLR is at the heart of the. NET framework, but I want to say that CTS and CLS are more important because they are the core of the CLR. In any programming language, if you want to execute on the. NET CLR, you must provide a compiler that compiles the program for that language into the metadata and IL that the. NET CLR knows, and conforms to the CTS rules. Not all languages are as consistent with the CTS specification as C #, after all, many languages appear earlier, and CTS appears behind, so there are some older languages that fail to conform to the CTS rules. This kind of language is in. NET has the following three ways to conform to the CTS specification:

-Change the language itself to comply with the CTS rules. For example, Visual Basic 6 has made a significant expansion and change, plus inherited features, which makes the new version of Visual Basic. NET almost a whole new language, as if C had been derived from the same year.

-The extension language itself is close to the CTS, but retains the syntax incompatible with the CTS, so that the CTS-compliant process is compiled in the same way that it does not conform to the CTS rules and is compiled into native code in the traditional manner. This is true for example, C + + with Managed Extension (abbreviated as mc++).

-The language itself is as constant as possible, and everything is achieved through a strong compiler design that is compatible with the CTS, Eiffel. For example, the CTS does not support multiple inheritance (multiple inheritance), but Eiffel supports multiple inheritance, and the Eiffel compiler can use interface and attribute to achieve multiple inheritance (this is quite ingenious, Interested readers may wish to look into it.)

OK, now let's look at the relationship between the three of them.


1) CTS Universal type System (Common type systems)

The CTS not only implements the variable compatibility type of COM, but also defines the type extension by means of user-defined types. Any to. NET platform as the target language must establish a mapping between its data type and the type of the CTS. All. NET language to share this type of system, to achieve seamless interoperability between them. The scheme also provides the inheritance between languages. For example, a user can derive a class written by C # in vb.net. We can think of CTS as the Superset (union) of all. NET languages, and the various languages that conform to CTS are actually just subset (intersection) of the CTS. The programs written by these languages, if you want to have the best compatibility to invoke each other (invoke) or inheritance, these languages must obtain a common subset, there is a common adherence to the specification, this is the CLS.


2) CLS Common Language Specification (Common Language specification)

Obviously, the difference between programming languages is not just the type. For example, some languages support multiple inheritance, some languages support unsigned data types, and some languages support operator overloading. Users should be aware of this, therefore. NET limits the interoperability issues raised by these differences by defining common language Specifications (Cls:common Language specification). The CLS has developed a minimal feature that must be supported by a language that targets the. NET platform, as well as the complete characteristics required for interoperability between the language and other. NET languages. Recognizing that this is important, the characteristic issues discussed here are not just simple grammatical differences between languages. For example, the CLS does not care about what keywords a language implements for inheritance, but only about how the language supports inheritance. The CLS is a subset of the CTS. This means that a language feature may conform to the CTS standard, but is beyond the scope of the CLS. For example, C # supports unsigned numeric types, which can pass the CTS test, but the CLS only recognizes symbolic numeric types. Therefore, if a user uses a C # unsigned type in a component, it may not be designed with languages that do not use unsigned types, such as vb.net. NET components for interoperability.

3) CLR Common language Runtime (Common Language Runtime)

To put it simply, the CLR is the implementation of the CTS, which means that the CLR is the application's execution engine and a fully functional class library, which is implemented in strict accordance with the CTS specification. As a program execution engine, the CLR is responsible for securely loading and running user program code, including garbage collection and security checks on unused objects. Code that runs under CLR monitoring, called Managed code (managed).

Reference: ". NET distributed Programming--c# chapter "

. The CTS, CLS, and CLR in net

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.