Difficulty: Easy
Correct Answer: The conditional logical operators && and || cannot be overloaded directly.
Explanation:
Introduction / Context:
This question tests precise knowledge of what C# allows (and forbids) in operator overloading. Many developers conflate operator overloading rules with behavior in other languages, so clarity here is essential for writing maintainable, correct code.
Given Data / Assumptions:
Concept / Approach:
Remember two key facts: (1) You cannot overload the conditional logical operators '&&' and '||' directly; instead, overloading '&' and '|' plus providing 'true' and 'false' operators enables short-circuit semantics. (2) Compound assignments (+=, -=, etc.) are not overloaded separately; they are translated by the compiler into the underlying binary operator plus assignment.
Step-by-Step Solution:
Verification / Alternative check:
Try declaring 'public static Type operator &&(Type a, Type b)'; the compiler rejects it. Implement an indexer with 'this[int i]'; no operator method is involved.
Why Other Options Are Wrong:
B misunderstands compound assignments; C leads to recursion; D is overly restrictive; E confuses indexers with operator overloading.
Common Pitfalls:
Assuming every visible operator token is overloadable; forgetting the special semantics for equality and conditional operators.
Final Answer:
The conditional logical operators && and || cannot be overloaded directly.
Discussion & Comments