Writing CLS-Compliant Code in C#

The syntax of C# ensures that many CLS rules can’t be broken. For example, C# doesn’t permit the declaration of global static fields or non-zero-based arrays, both requirements of CLS compliance. However, some CLS rules can’t be enforced by the language, and guaranteeing that they’re followed is the responsibility of the programmer. The following list highlights some key requirements of writing CLS-compliant code in C#:

  • Case must not be used to differentiate between program element identifiers such as member names.

  • All member parameter and return types must be CLS-compliant; this means the following simple types cannot be used: sbyte, ushort, uint, and ulong.

  • Pointer types and function pointers aren’t CLS-compliant. ...

Get C# for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.