.net – the ‘CLSCompliant’ attribute in .NET

cls-compliantnet

What is the CLSCompliant attribute?

Best Answer

You mark classes with the CLSCompliant attribute when you want to make sure it can be used by any other .NET language.
These are the basic rules:

  1. Unsigned types should not be part of the public interface of the class. What this means is public fields should not have unsigned types like uint or ulong, public methods should not return unsigned types, parameters passed to public function should not have unsigned types. However unsigned types can be part of private members.

  2. Unsafe types like pointers should not be used with public members. However they can be used with private members.

  3. Class names and member names should not differ only based on their case. For example we cannot have two methods named MyMethod and MYMETHOD.

  4. Only properties and methods may be overloaded, operators should not be overloaded.