Compiler error · error CS0019
Operator 'X' cannot be applied to operands of type 'Y' and 'Z'
The operator exists — but not for those two types. C# never coerces across unrelated types to make an operator fit, so it names the operator and both sides and stops.
See it happen: subtracting from text
string label = "Total: ";
int count = 3;
Console.WriteLine(label - count); // you cannot subtract a number from text
Notice the asymmetry that confuses everyone: label + count is perfectly legal (string concatenation), but - has no string overload. The + operator was overloaded for strings; the arithmetic ones were not.
Cause 1: doing math on a string
Text that looks like a number is still text. Parse it first:
string a = "10";
string b = "3";
Console.WriteLine(int.Parse(a) - int.Parse(b)); // parse, then subtract
Cause 2: comparing incompatible types
int number = 5;
string text = "5";
Console.WriteLine(number < text); // ordering needs both sides comparable
Fix: convert so both sides share a type. (For equality you can compare a string to a literal, but ordering — <, > — needs numbers on both sides.)
int number = 5;
string text = "5";
Console.WriteLine(number < int.Parse(text)); // now both are int
Cause 3: arithmetic on bool
bool ready = true;
Console.WriteLine(ready + 1); // bool is not a number in C#
If you meant "count it as 1 or 0", say so:
bool ready = true;
int asNumber = ready ? 1 : 0; // explicit: true→1, false→0
Console.WriteLine(asNumber + 1);
Cause 4: char arithmetic surprises
char is a number underneath, so 'a' + 1 is fine (gives 98) — but adding two char gives an int, not a char, which can surprise you when you assign it back:
char a = 'x';
char b = 'y';
char sum = a + b; // char + char is an int — not a char
Frequently asked
What does CS0019 mean?
The operator cannot work with those operand types. The message names the operator and both types. Convert one side to a compatible type.
Why does + work with strings but - doesn't?
C# overloads + for strings as concatenation. Subtraction has no string overload, so it refuses. Parse the string first to do arithmetic.
Checklist
- Look at both operand types in the message — are they even the same kind of thing?
- Text with digits is still
string:int.Parse/double.Parsebefore arithmetic. boolis not a number — usecond ? 1 : 0when you mean to count it.- Remember
char + charisint; cast back with(char)if you need a character. - For ordering comparisons, both sides must be the same comparable type.