Equality and Assigment Operators
Posted
by
Jeremy Smith
on Stack Overflow
See other posts from Stack Overflow
or by Jeremy Smith
Published on 2012-11-13T22:40:56Z
Indexed on
2012/11/13
23:00 UTC
Read the original article
Hit count: 396
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?
© Stack Overflow or respective owner