Show/Hide Toolbars

XSharp

Operator 'operator' cannot be applied to operands of type 'type' and 'type'

 

A binary operator is applied to data types that do not support it. For example, you cannot use the || operator on strings, you cannot use + , - , < , or > operators on bool variables, and you cannot use the == operator with a struct type unless the type explicitly overloads that operator.

 

If you encounter this error with a class type, it is because the class does not overload the operator. For more information, see Overloadable Operators.

Example

 

In the following example, XS0019 is generated in two places because bool in X# is not convertible to int. XS0019 also is generated when the subtraction operator is applied to a string. The addition operator (+) can be used with string operands because that operator is overloaded by the String class to perform string concatenation.

 

 

 

 

Example

 

In the following example, conditional logic must be specified outside the ConditionalAttribute. You can pass only one predefined symbol to the ConditionalAttribute.

The following sample generates XS0019.