.NET Framework CLR: What is the Common Language Specification?
Q: What is the Common Language Specification?
A: The Common Language Specification (CLS) describes a set of features that different languages have in common. It defines the mininum requirements of types that must be supported by any .NET language.
- What is CLS compliance?
The Common Type System defines a set of rules compilers must follow for types (both value and reference) so that objects of types written in different languages can interact. But not all types are available in all languages, so to make a type useable from all .NET languages the rules of CLS. In other words it must be CLS compliant.
- What are the rules of CLS?
The most important rules, and which apply to public and protected members are:
- All types appearing in a method prototype must be CLS-compliant.
- Array elements must have a CLS-compliant element type. Arrays must also be 0-indexed.
- A CLS compliant class must inherit from a CLS-compliant class.
- System.Object is CLS compliant.
- Although method names in CLS-compliant classes are not case-sensitive, no two method names can be different only in the case of the letters in their name.
- Enumerations must be of type Int16, Int32, or Int64. Enumerations of other types are not compliant.
- Also there are several naming guidelines, but they are not mandatory.
- Can I have an example of non-CLS compliance?
For instance, unsigned types are supported by C# and MC++ but not by VB.NET (except for 'Byte', which is mapped on .NET's 'Byte' and takes values from 0 t o255). So, any public or protected member of a C# class that has an unsigned type or takes as parameter an unsigned is not CLS compliant.