Why should I write CLS-compatible code?

I have found many CLS compliance pages.

I realized that CLS correspondence:

  • It is a way to guarantee compatibility with other assemblies .
  • Is a way to declare a high security code.

Many peolple write that "if you are writing code, you must write it CLS-compatible." But, as far as I can read, there is no reason to use CLS compatibility in general software.

Am I right or am I missing something?

+48
c # cls-compliant
Dec 01 '09 at 20:11
source share
4 answers

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

+40
Dec 01 '09 at 20:15
source share

CLS compliance is especially important if you distribute libraries - in particular, when writing CLS-compatible, it ensures that your libraries will be used in all CLS-compatible languages.

For example, Visual Basic is not case sensitive, whereas C #. One of the requirements for complying with the CLS is that the public (and protected) names of the participants should not differ only depending on the case, thereby ensuring that your libraries can be safely used using Visual Basic code or any other .NET language that does not differ from case.

+31
Dec 01 '09 at 20:18
source share

There can be no specific reason for your code to be compatible with CLS, but people cite the fact that it is "best practice" - something that you should do, because it is a good habit, and not be noticeably better for a specific scenario.

In other words, it is recommended that you make your CLS code compatible if you have no reason to.

+11
Dec 01 '09 at 20:15
source share

The answer is to ensure maximum compatibility between .NET languages. CLS is a lingua franca that allows C # assemblies to work with F #, Iron Python, C ++ / CLI, VB.NET, Boo, and all other .NET languages. A step outside this boundary, and your assembly may work correctly, but not necessarily.

+10
Dec 01 '09 at 20:16
source share



All Articles