VII. Public language specification (CLS)

Source: Internet
Author: User
CLR integrates many languages and enables mutual access between them because the CLR establishes a standard type set, metadata, and public execution environment. However, there are great differences between different languages, such as case sensitivity. Some do not support unsigned, Operator overloading, or variable parameters. Therefore, to create a method that allows access by other languages Program , Your own Programming Language Only those features supported by other languages can be used. To help us better achieve this, Microsoft defines a "common language specification (CLS)", such

If a language defines a type and you want to use this type in another language, it is absolutely impossible to use any CLS external features in the public and protected members of this type. Otherwise, other programmers use other languages to writeCodeYou may not be able to access members of this type. Run the following code:

using system;
// tells the compiler to check CLS compatibility.
[Assembly: clscompliant (true)]
namespace somelibrary
{< br> // the alarm is triggered, because the class is public
Public sealed class somelibrarytype
{< br> // warning, the returned value does not conform to CLS
Public uint32 ABC ()
{< br> return 0;
}< br> // warning. CLS is not applicable only when the case sensitivity is different.
Public void ABC ()
{

}
// No error. This method is private.
Private uint32 ABC ()
{
Return 0;
}
}
}

In this case, a warning will appear, because its public and protected members do not comply with the CLS feature. To obtain a complete list of CLS rules, see. "Cross-language interoperability" section of the Net Framework SDK documentation.
If the above Code removes the public modifier of the somelibrarytype class, all warnings will disappear, because this class will use the default modifier internal, so it is invisible outside the assembly. By the way, it cannot be changed to private, protected, or protected internal, because the elements defined in the namespace cannot be explicitly declared as private, protected, or protected internal.

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.