Skip to main content

How to Resolve Error "CS1019: Overloadable unary operator expected" in C#

The Compiler Error CS1019 is a syntax error related to Operator Overloading. The message reads: "Overloadable unary operator expected".

In C#, operators are categorized by how many arguments they take:

  • Unary Operators (1 Argument): +, -, !, ~, ++, --, true, false.
  • Binary Operators (2 Arguments): +, -, *, /, %, ==, !=, <, >, etc.

This error occurs when you define an operator overload method with one parameter (a unary signature), but the symbol you provided (e.g., * or ==) is not a valid unary operator in C#. The compiler sees one argument and expects a symbol from the unary list; when it finds a binary-only symbol (or an invalid keyword), it raises CS1019.

This guide explains which operators can be overloaded as unary and how to fix signature mismatches.

Understanding Overloadable Unary Operators​

When you declare an operator with a single parameter: public static ReturnType operator Symbol(ParamType p)

The Symbol must be one of the following:

  • + (Unary Plus, e.g., +a)
  • - (Unary Negation, e.g., -a)
  • ! (Logical Negation, e.g., !a)
  • ~ (Bitwise Complement, e.g., ~a)
  • ++ (Increment)
  • -- (Decrement)
  • true / false (Boolean evaluation)

Any other symbol (like *, /, ==) requires two parameters.

Scenario 1: Overloading Binary Operators as Unary​

This is the most common cause. You might be trying to define multiplication (*), but you forgot the second parameter, or you might be trying to define a C++ style pointer dereference (unary *), which is not overloadable in C#.

Example of error​

Defining the multiplication operator * with only one argument.

public class Vector
{
public int X { get; set; }

// ⛔️ Error CS1019: Overloadable unary operator expected.
// The compiler sees 1 parameter ('Vector a').
// It expects '+', '-', '!', etc.
// It found '*', which is strictly binary (Multiplication) in C# operator overloading.
public static Vector operator *(Vector a)
{
return new Vector { X = a.X * 2 };
}
}

Solution: Add the Second Parameter​

If you meant to define multiplication, you need two operands.

public class Vector
{
public int X { get; set; }

// ✅ Correct: Binary operator takes two parameters.
public static Vector operator *(Vector a, int scalar)
{
return new Vector { X = a.X * scalar };
}
}

Solution: Use a Valid Unary Operator​

If you actually meant to perform an operation on a single object (like negation), use a supported unary symbol.

public class Vector
{
public int X { get; set; }

// ✅ Correct: '-' is a valid unary operator.
public static Vector operator -(Vector a)
{
return new Vector { X = -a.X };
}
}

Scenario 2: Syntax Errors in Conversion Operators​

Sometimes developers confuse standard Operator Overloading with Conversion Operators (implicit / explicit). If you omit the implicit or explicit keyword, the syntax looks like a malformed unary operator definition.

Example of error​

Trying to define a conversion to int without the conversion keywords.

public class Money
{
public decimal Amount { get; set; }

// ⛔️ Error CS1019: Overloadable unary operator expected
// The compiler sees 'operator int(...)'.
// It thinks 'int' is supposed to be a symbol like '++'.
// Since 'int' is a type, not an operator symbol, it fails.
public static operator int(Money m)
{
return (int)m.Amount;
}
}

Solution: Add implicit or explicit​

Conversions are defined differently than standard operators.

public class Money
{
public decimal Amount { get; set; }

// ✅ Correct: Added 'explicit' keyword.
// This defines a cast: (int)myMoney
public static explicit operator int(Money m)
{
return (int)m.Amount;
}
}

Conclusion​

CS1019 indicates a mismatch between the number of parameters and the operator symbol.

  1. Count Parameters: Do you have one parameter?
  2. Check Symbol: Is the symbol +, -, !, ~, ++, --, true, or false?
    • No: You are likely trying to use a binary operator (like * or /) with missing arguments.
    • Syntax Check: If you are trying to convert types, ensure you used the implicit or explicit keyword.