0

The folloging is from a book on C#.

To illustrate, the following Add() method is not CLS-compliant, as the parameters and return values make use of unsigned data (which is not a requirement of the CLS):

class Calc
{
// Exposed unsigned data is not CLS compliant!
public ulong Add(ulong x, ulong y)
{ return x + y;}
}

What does this mean? How can function not take ulong value? Is that not covered in CLS (Common Language Specification) for C#?

I did try the example and it builds and runs fine. I thought passing a ulong argument is very basic. What does this paragraph rally means?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
zar
  • 11,361
  • 14
  • 96
  • 178
  • What book is that? What comes before `To illustrate`? – zaitsman Aug 07 '20 at 05:44
  • CLS compliance is not about C#, but about any other language based on CLR. See https://learn.microsoft.com/en-us/dotnet/standard/language-independence-and-language-independent-components – Klaus Gütter Aug 07 '20 at 06:01

1 Answers1

2

It means that some other flavor of .NET might not be able to use that method, because it doesn't have support for unsigned data types. .NET isn't only C#; there are many syntaxes that compile to the same underlying thing as C# does - one of the appeals of .NET is that if someone wrote a compiler for your favorite programming syntax (say, COBOL) that produces .NET IL then you can write your COBOL, you can use libraries written in C#, you can even have them side by side in the same solution (try it; put a vb.net and a c# project in a solution, reference one from the other and debug it - the debugger will happily step back and forth between the two)

Whether CLS the compliance rules are too strict these days is a subject of some debate, but if you're writing something and want to be sure all the flavors support what you write, you mark your assembly as CLS compliant and stick to the rules

Caius Jard
  • 72,509
  • 5
  • 49
  • 80