Reputation: 7520
I am getting a System.StackOverFlowException when the code hits this function.
Where stringtype is user defined tupe and equals int the function in the type library.
public static bool Equals(StringType leftHand, StringType rightHand)
{
if (leftHand == rightHand)
{
return true;
}
if ((leftHand == "0") || (rightHand == "0"))
{
return false;
}
return (leftHand.myValue.Equals(rightHand.myValue) && leftHand.myState.Equals(rightHand.myState));
}
Upvotes: 3
Views: 13306
Reputation: 111920
This
if (leftHand == rightHand)
change to
if (object.ReferenceEquals(leftHand, rightHand))
You probably redefined the ==
operator to call Equals
.
And I hope you don't have an implicit operator that from string
creates StringType
, because otherwise
if ((leftHand == "0") || (rightHand == "0"))
will probably call itself for the same reason.
Probably
if ((leftHand.myValue == "0") || (rightHand.myValue == "0"))
would be better.
Upvotes: 10