Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

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.
bool result = leftOperand > rightOperand;

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.
double x = double.NaN;
double y = 5.0;
bool result = x > y; // Evaluates to 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.
public readonly struct Measurement
{
    public double Value { get; }

    public Measurement(double value) => Value = value;

    // Overloading the > operator
    public static bool operator >(Measurement left, Measurement right)
    {
        return left.Value > right.Value;
    }

    // The < operator must also be overloaded
    public static bool operator <(Measurement left, Measurement right)
    {
        return left.Value < right.Value;
    }
}

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.
Master C# with Deep Grasping Methodology!Learn More