C# › Indexers & Operator Overloading
Which operators can be overloaded in C#, and which ones (like && and ||) generally CANNOT be overloaded directly?
IntermediateAnswer
You can overload most unary and binary operators (+, -, *, /, ==, !=, <, >, etc.), true/false, and implicit/explicit conversion operators — but && and || specifically CANNOT be overloaded directly (they're derived automatically from overloading & and | plus true/false operators), and assignment operators like = can never be overloaded at all.
public static Vector operator +(Vector a, Vector b) => new(a.X + b.X, a.Y + b.Y); // OK
public static Vector operator *(Vector v, double scalar) => new(v.X * scalar, v.Y * scalar); // OK
// public static Vector operator &&(Vector a, Vector b) { } // NOT directly overloadableReal-world example Deciding which operators genuinely make semantic sense to overload for a custom Vector, Money, or Complex number type.