Skip to main content
The > (greater than) operator is a binary relational operator that evaluates whether its left-hand operand is strictly greater in value than its right-hand operand. It returns a bool value: true if the left operand is greater, and false otherwise.

Supported Built-in Types

The C# compiler provides built-in implementations of the > operator for the following types:
  • Numeric Types: All integral (sbyte, byte, short, ushort, int, uint, long, ulong, nint, nuint) and floating-point (float, double, decimal) types.
  • Characters: When applied to char operands, the operator compares their underlying 16-bit Unicode integer values.
  • Enumerations: When applied to enum types, the operator compares the underlying integral values of the enumeration members.

Floating-Point NaN Behavior

When comparing floating-point types (float or double), if either the left operand, the right operand, or both evaluate to NaN (Not a Number), the > operator strictly returns false.

Operator Precedence and Associativity

  • Precedence: The > operator falls into the relational and type-testing operators category. It is evaluated after arithmetic operators (+, -, *, /) and shift operators (<<, >>), but before equality operators (==, !=) and logical operators (&&, ||).
  • Associativity: It evaluates from left to right.

Operator Overloading

User-defined types (class, struct, or record) can overload the > operator to define custom comparison logic. By C# language design rules, the > and < operators are a matched pair. If a type overloads the > operator, it must also explicitly overload the < (less than) operator.

Lifted Operators for Nullable Types

For nullable value types (T?), the > operator is “lifted.” If either or both operands are null, the > operator evaluates to false. If both operands have values, it unwraps them and applies the underlying > operator of type T.
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More