Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I write CLS compliant code?

I've found a lot of pages about CLS compliance.

I've understood that CLS compliance:

  • Is a way to guarantee different assembly compatibility.
  • Is a way to declare the high security code

Many peolple write that "if you write code, you should write it CLS compliant." But as far I can read, there is no reason to use CLS compliance in generic software.

Am I right, or did I miss something?

like image 853
Luca Avatar asked Dec 01 '09 20:12

Luca


People also ask

Why is CLS compliant?

Being CLS compliant means that you can write code that can be consumed by any language that can be compiled and run on the CLR.

Which is not a CLS compliant language?

CLS compliance has to do with interoperability between the different . NET languages. The property is not CLS compliant, because it starts with an underscore and is public (note: protected properties in a public class can be accessed from outside the assembly).


2 Answers

If you write a library or framework it makes sense to ensure your library can be used from any CLR language.

like image 131
Remus Rusanu Avatar answered Sep 30 '22 17:09

Remus Rusanu


CLS-compliance is particularly important if you're distributing libraries - specifically, writing CLS compliant guarantees that your libraries will be usable by all CLS-compliant languages.

For instance, Visual Basic is not case-sensitive, whereas C# is. One of the requirements of CLS compliance is that public (and protected) member names should not differ only by case, thus ensuring that your libraries can be used safely by Visual Basic code, or any other .NET language that doesn't differentiate based on case.

like image 40
Dathan Avatar answered Sep 30 '22 18:09

Dathan