In the past two days, when I use the equal operator of C # to overload the following problem, it will lead to an endless loop. Do you know if there is a better solution? Because it is necessary to determine whether the parameter is null, it will use = to compare with null, so that the operator overload is called, resulting in an endless loop. I don't know if there are other methods except = to judge whether an object is null? Please also advise :)
Public class columndatatype
{
Public static bool areequal (columndatatype type1, columndatatype type2)
{
If (type1 = NULL | type2 = NULL) // here the method that is reloaded by the operator is called, leading to an endless loop!
{
Return false;
}
Else if (type1. _ primitivetype = type2. _ primitivetype
& Type1. _ parameter1 = type2. _ parameter1
& Type1. _ parameter2 = type2. _ parameter2)
{
Return true;
}
Else
{
Return false;
}
}
Public static bool operator = (columndatatype type1, columndatatype type2)
{
Return columndatatype. areequal (type1, type2 );
}
Public static bool Operator! = (Columndatatype type1, columndatatype type2)
{
Return! Columndatatype. areequal (type1, type2 );
}
}