Operator overloading

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Operator overloading

Post by wriedmann »

Hello,

is it possible to overload operators? Somewhere in the help it is mentioned, but I was not able to do it.

Code: Select all

static method operator == ( self oMaster as efCrmTab, oItem as efCrmTab ) as logic
Thank you very much!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Operator overloading

Post by wriedmann »

Hello,

I have found my error: the word "method" has to be removed:

Code: Select all

static operator == ( self oMaster as efCrmTab, oItem as efCrmTab ) as logic
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Operator overloading

Post by wriedmann »

Hello,

to complete the issue for others:

If you implement the == operator, you have also to implement the != operator and the Equals() and GetHashCode() methods:

Code: Select all

static operator == ( self oMaster as efCrmTab, oItem as efCrmTab ) as logic 

static operator != ( self oMaster as efCrmTab, oItem as efCrmTab ) as logic 

public method Equals( oItem as object ) as logic 

method GetHashCode() as int
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply