What is the 'CLSCompliant' attribute in .NET?
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:
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
orulong
, 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.Unsafe types like pointers should not be used with
public
members. However they can be used withprivate
members.Class names and member names should not differ only based on their case. For example we cannot have two methods named
MyMethod
andMYMETHOD
.Only properties and methods may be overloaded, operators should not be overloaded.
It tells other consumers of your code that it is CLS compliant, and also makes the C# compiler check that it's CLS compliant for you.
The referenced article contains a lot more detail about what CLS compliance entails.