Equality Operator Overloading

Source: Internet
Author: User

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 );

}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.