Re-learn. Net  -- multi-language support for CLR
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
As we all know, CLR supports a variety of languages, including C #, VB. NET, and so on (to be exact, it should be that all languages can provide compilers to run on CLR ). To support multiple languages, CLR must establish a mode so that various languages can easily run on it. Although the syntax of various object-oriented languages is different, their core semantics is similar. Therefore, CLR uses this point, and all its content is centered around the type. The common type system cts of CLR is used to describe the type definition and behavior.
In short, CTS defines some types, which are divided into two types: Value Type and reference type. Value types include int32, Boolean, and structure, which are allocated on the runtime stack. Reference types include class, interface, array, and so on, which are allocated in the managed heap (I believe that people who have learned oo will not be unfamiliar with this ). Each type may have some members (0 to N), including fields, methods, attributes, and events. At the same time, each type uses some access control permissions, such as public and private. In addition, CTS also specifies some rules, such as: All types must be inherited from objects, and single inheritance is supported. All these type settings and Rules constitute CTS. Once a language is compiled, the CLR can run as long as it meets the CTS requirements. Therefore, to run a language on the CLR, it must comply with the rules and restrictions of CTS (for example, if C ++ needs to compile and run on the CLR, it must change its multi-inheritance mode ).
At the same time, CTS is so huge that no language can support all its features (including C # and VB), and CLR does not have this requirement. This will cause a problem. How can libraries written in one language be called by other languages? Assume that a language supports uint64 and implements a library with the public int64 getint () method (). At this time, another language is Program This method is intended to be called in the design, but it does not support uint64, so that it cannot be used at all. This is obviously different from the concept of CLR multi-language support.
To achieve multi-language communication, a general language specification CLS is also required, which is a subset of CTS. All languages running on CLR must fully support Cls. For example, CLS has int16 but does not require uint64 (supported in CTS). To run a language on CLR, it must support int16, but not uint64. This also tells us that if you want your class library and framework to be called by all languages that support CLR, you must only publish interfaces in CLS specifications, of course, you can use all types supported by CTs for programming internally.
To put it bluntly, CTS is a day. It embraces everything. CLS is a place and must stand on it. Most languages are between the two (CLS superset, a subset of CTS). It can be said that it is awesome (Sorry, it is a bit bad, please bring your own garbage bag ^_^ ).
Every time I think about this question, I have a doubt. Is it true that C # and VB. NET must have the same twins? (although their syntax habits are different, the supported features and features are almost like dead ends )? Of course, Microsoft has commercial considerations, but I still miss the simple VB era. I always think that the VB. NET syntax should be simpler, better entry, and more efficient in development. It is said that the feature set of VB. NET and C # Will be separated in the future. Well, I hope this is true.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.