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.