CTS, CLS, and CLR in. NET

Source: Internet
Author: User

 

In the process of learning. NET, we will inevitably come into contact with these three concepts. What are these three things and their relationships? During the learning process, we may pay too much attention to CLR because CLR is. NET Framework core, but what I want to talk about is that CTS and CLS are more important, because they are the core of CLR. Any programming language, if you want. net clr, you must provide a compiler to compile the program in this language. net clr recognizes metadata and IL, which comply with CTS regulations. Not all languages can comply with the CTS specifications as C # does. After all, many languages appear first and CTS appears later, so some old languages do not comply with the CTS rules. This type of language complies with the CTS specification in. NET in three ways:-change the language itself to comply with the CTS specification. For example, Visual Basic 6 has been greatly expanded and changed, and the inherited features make the New Visual Basic. NET is almost a brand new language, just as C ++ was derived from C. -The Extended Language is similar to the CTS but still retains the syntax that is incompatible with the CTS. As a result, the program will compile in the CTS mode that complies with the CTS regulations, otherwise, native code is compiled in the traditional mode. For example, C ++ with Managed Extension (MC ++. -The language itself should be kept unchanged as much as possible. Everything is achieved through a super-powerful compiler design that is compatible with CTS. That is how Eiffel works. For example, CTS does not support multiple inheritance, but Eiffel supports multi-inheritance. the compiler of Eiffel can use interfaces and attributes to achieve multi-inheritance (this method is quite clever, interested readers may wish to study it ). Okay. Now let's take a look at the relationship between them. 1) CTS Common Type System CTS not only implements the COM variable compatibility Type, but also defines the Type extension through user-defined Type. Any language targeting the. NET platform must map its data type to the CTS type. All. NET languages share this type of system to achieve seamless interoperability between them. This solution also provides inheritance between languages. For example, you can derive a class written by C # In VB. NET. We can regard CTS as the superset (union) of all. NET languages, and the various languages that comply with CTS are actually just the subset (intersection) of CTS ). For programs written in these languages to have the best compatibility for mutual invocation or inheritance, a common subset must be obtained between these languages and a compliant specification, this is CLS. 2) Common Language Specification (CLS) It is clear that the difference between programming languages is not just the type. For example, some languages support multi-inheritance, some languages Support unsigned data types, and some languages Support Operator overloading. The user should be aware of this, so. NET limits the interoperability problems caused by these differences by defining the Common Language Specification (CLS: Common Language Specification. CLS defines the minimum features that must be supported by a language targeting the. NET platform, and the complete features required for interoperability between the language and other. NET languages. Recognizing this is very important. The feature issues discussed here are not just simple syntax differences between languages. For example, CLS does not focus on the keywords used to implement inheritance in a language. It only cares about how the language supports inheritance. LS is a subset of CTS. This means that a language feature may comply with the CTS standards, but beyond the scope of CLS. For example, C # supports the unsigned numeric type. The feature can pass the CTS test, but CLS only recognizes the symbolic numeric type. Therefore, if you use the C # unsigned type in a component, you may not be able to use a language that does not use the unsigned type (such as VB.. NET.. NET component to achieve interoperability. 3) The Common Language Runtime (CLR) indicates that CLR is the implementation of CTS. That is to say, CLR is the execution engine of applications and a class library with complete functions, this class library is implemented in strict accordance with CTS specifications. As a program execution engine, CLR is responsible for securely loading and running user program code, including garbage collection and security checks for unused objects. The code running under CLR monitoring is called managed code ). Reference:. NET distributed programming-C #

In the process of learning. NET, we will inevitably come into contact with these three concepts. What are these three things and their relationships? During the learning process, we may pay too much attention to CLR because CLR is. NET Framework core, but what I want to talk about is that CTS and CLS are more important, because they are the core of CLR. Any programming language, if you want. net clr, you must provide a compiler to compile the program in this language. net clr recognizes metadata and IL, which comply with CTS regulations. Not all languages can comply with the CTS specifications as C # does. After all, many languages appear first and CTS appears later, so some old languages do not comply with the CTS rules. This type of language complies with the CTS specification in. NET in three ways:

 

-Change the language itself to comply with CTS regulations. For example, Visual Basic 6 has been greatly expanded and changed, and the inherited features make the New Visual Basic. NET is almost a brand new language, just as C ++ was derived from C.

 

-The Extended Language is similar to the CTS but still retains the syntax that is incompatible with the CTS. As a result, the program will compile in the CTS mode that complies with the CTS regulations, otherwise, native code is compiled in the traditional mode. For example, C ++ with Managed Extension (MC ++.

 

-The language itself should be kept unchanged as much as possible. Everything is achieved through a super-powerful compiler design that is compatible with CTS. That is how Eiffel works. For example, CTS does not support multiple inheritance, but Eiffel supports multi-inheritance. the compiler of Eiffel can use interfaces and attributes to achieve multi-inheritance (this method is quite clever, interested readers may wish to study it ).

 

Okay. Now let's take a look at the relationship between them.

1) CTS Common Type System)

CTS not only implements the COM variable compatibility type, but also defines the type extension through user-defined types. Any language targeting the. NET platform must map its data type to the CTS type. All. NET languages share this type of system to achieve seamless interoperability between them. This solution also provides inheritance between languages. For example, you can derive a class written by C # In VB. NET. We can regard CTS as the superset (union) of all. NET languages, and the various languages that comply with CTS are actually just the subset (intersection) of CTS ). For programs written in these languages to have the best compatibility for mutual invocation or inheritance, a common subset must be obtained between these languages and a compliant specification, this is CLS.

2) Common Language Specification)

Obviously, the difference between programming languages is not just type. For example, some languages support multi-inheritance, some languages Support unsigned data types, and some languages Support Operator overloading. The user should be aware of this, so. NET limits the interoperability problems caused by these differences by defining the Common Language Specification (CLS: Common Language Specification. CLS defines the minimum features that must be supported by a language targeting the. NET platform, and the complete features required for interoperability between the language and other. NET languages. Recognizing this is very important. The feature issues discussed here are not just simple syntax differences between languages. For example, CLS does not focus on the keywords used to implement inheritance in a language. It only cares about how the language supports inheritance. CLS is a subset of CTS. This means that a language feature may comply with the CTS standards, but beyond the scope of CLS. For example, C # supports the unsigned numeric type. The feature can pass the CTS test, but CLS only recognizes the symbolic numeric type. Therefore, if you use the C # unsigned type in a component, you may not be able to use a language that does not use the unsigned type (such as VB.. NET.. NET component to achieve interoperability.

 

3) Common Language Runtime)

To put it simply, CLR is the implementation of CTS. That is to say, CLR is the execution engine of the application and a class library with complete functions. This class library is strictly implemented in accordance with the CTS specifications. As a program execution engine, CLR is responsible for securely loading and running user program code, including garbage collection and security checks for unused objects. The code running under CLR monitoring is called managed code ).

Reference:. Net distributed programming-C #

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.