Link to home
Start Free TrialLog in
Avatar of igor92128
igor92128

asked on

Overloading == stack overflow exception

I'm trying to overload the == and != operators.

 public static bool operator ==(VeryLargeInt value1, VeryLargeInt value2)
        {
            if ((value1 == null) || (value2 == null))
            {
                throw new ArgumentNullException();
            }
            return value1.Equals(value2);
        }

        public static bool operator !=(VeryLargeInt value1, VeryLargeInt value2)
        {
            return !(value1 == value2);
        }

But the code above generates a unhandled exception of 'System.StackOverflowException'. How do I remedy this?
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]
just make the == like this:

 public static bool operator ==(VeryLargeInt value1, VeryLargeInt value2)
        {
            return value1.Equals(value2);
        }

 if eiter value is null, that will raise an error anyhow...