The Role of the Common Language Specification (CLS) The Common Language Specification (CLS) is a subset of the CTS. The CLS defines the minimal features a language must support to be considered a .NET language. If a complier abides by the CLS rules, all other .NET languages can use the resulting binaries in a uniform manner. By and large, only developers creating a new .NET language need to engross themselves in the full details of the CLS. Nevertheless, it is enlightening to examine some of these rules firsthand.
CLS rule: All classes ultimately derive from System.Object:
For the time being, don’t concern yourself with the exact syntax seen below. We will see the details of System. Object later in this class. // The top-most class in the .NET world: System.Object public class Object { // Reference equality by default. Override for value semantics. public virtual bool Equals(object obj); // Get hash value for object. public virtual int GetHashCode(); // RTTI for this object. public Type GetType(); // Override to produce state data in string format. public virtual string ToString(); // Override to cleanup resources (non-deterministic destruction) protected virtual void Finalize(); // System.Object also defines two static functions. public static bool Equals(object objA, object objB); public static bool ReferenceEquals(object objA, object objB); }
CLS rule: Every class has exactly one base class but may implement multiple interfaces.
Like Java, the CLS does not support multiple inheritance for class types. C++ developers take note. Like Java, the CLS allows a class to implement multiple interfaces. It is possible for an interface to have multiple base interfaces. In other words, multiple interface inheritance is supported.
CLS rule: Every type in an assembly must specify its visibility. Although a given language may have unique keywords, the basic visibility settings are:
Public: visible to anyone, anywhere.
Private: only visible to members of the defining type.
Protected: only visible to members of the defining type or members of derived types.
Internal: visible to any type defined within the assembly. In VB, internal visibility is defined using the Friend keyword.
CLS rule: All data points must map to the types defined by the CTS.
The CTS defines a set of core data types, each of which has a corresponding object in the System namespace. As far as the type system itself is concerned, a type can be from the set {class, interface, structure, enumeration, delegate}. Since the release of .NET 2.0, all types but enumerations may be created generically.
Common Language Specification (CLS)
Table of Contents
C# Tutorial | C#.NET Tutorial | CLS Tutorial
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.