What is the CLSCompliant
attribute?
.net – the ‘CLSCompliant’ attribute in .NET
cls-compliantnet
Related Topic
- C# – the difference between const and readonly in C#
- C# – How to enumerate an enum
- C# – What are the correct version numbers for C#
- .net – the best algorithm for overriding GetHashCode
- C# – How to get a consistent byte representation of strings in C# without manually specifying an encoding
- .net – Difference between decimal, float and double in .NET
- C# – a NullReferenceException, and how to fix it
- .net – the difference between .NET Core and .NET Standard Class Library project types
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:
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.