Unary operator overloading in C#.NET — which unary operators among the list are overloadable?

Difficulty: Easy

Correct Answer: true, false, and unary + can be overloaded.

Explanation:

Introduction / Context:C# permits overloading many unary operators to customize semantics for user-defined types.

Given Data / Assumptions:

  • Operators under consideration: true, false, +, new, is.

Concept / Approach:Overloadable unary operators include +, -, !, ~, ++, --, true, and false. Keywords new and is are not overloadable operators.

Step-by-Step Solution:

1) true/false: overloadable to support custom truthiness on types.2) unary +: overloadable; often paired with binary + overloads.3) new: not an operator you can overload.4) is: not overloadable.

Verification / Alternative check:Compile a struct with public static bool operator true(...) and public static bool operator false(...).

Why Other Options Are Wrong:B and D include non-overloadable keywords; C is incomplete.

Common Pitfalls:Confusing language keywords with overloadable operators.

Final Answer:true, false, and unary + can be overloaded.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion