[Solved] When CLSCompliant(true) , Operators should not be overloaded C#?


CLS stands for Common Language Specification. The thing is that CLS is a subset of IL features which is supported by all .NET languages. In short, not every .NET language supports operator overloading. That’s why it is considered by the compiler as not CLS compliant.

Update
For example VB.NET does not support operators overloading.

Consider the following example:

public struct DateTime 
{
   public static TimeSpan operator -(DateTime t1, DateTime t2) { }
   public static TimeSpan Subtract(DateTime t1, DateTime t2) { }
}

In C# you can do the following:

DateTime dt1 = new DateTime();
DateTime dt2 = new DateTime();
DateTime dt3 = dt2 - dt1;

In VB.NET you are not allowed to do that. In VB.NET you will use

DateTime dt1 = new DateTime();
DateTime dt2 = new DateTime();
DateTime dt3 = dt2.Subtract(dt1);

2

solved When CLSCompliant(true) , Operators should not be overloaded C#?