Equality and Assigment Operators
- by Jeremy Smith
I have a assembly compiled in VB.NET that contains two operators:
Public Shared Operator =(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean
Return quarterA.StartDate = quarterB.StartDate AndAlso
quarterA.EndDate = quarterB.EndDate AndAlso
quarterA.Quarter = quarterB.Quarter
End Operator
Public Shared Operator <>(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean
Return Not (quarterA = quarterB)
End Operator
However, when using the assembly in C# to perform equality checks if (qtr != null) I receive the error:
Cannot implicity convert type 'object' to 'bool'
My original intent with the = operator was only for assignment purposes in VB, so I may be way off base (I don't use custom operators too often).
What do I need to do to make the operator behave with both equality and assignment operations?