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.StackOverflowExcep tion'. How do I remedy this?
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.StackOverflowExcep
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
public static bool operator ==(VeryLargeInt value1, VeryLargeInt value2)
{
return value1.Equals(value2);
}
if eiter value is null, that will raise an error anyhow...