overloading binary operators |
Top Previous Next |
New features since Delphi 7 > Operator Overloading > binary operators
The translation of overloaded binary operators is straightforward. This is shown in the following example:
class operator TMyClass.Add(a, b: TMyClass): TMyClass; var returnrec : TMyrClass; begin returnrec.payload := a.payload + b.payload; Result:= returnrec; end;
becomes in C# to:
public static TOperatorClass operator + (TOperatorClass a, TOperatorClass b) { TOperatorClass result = TOperatorClass.CreateRecord(); TOperatorClass returnrec = TOperatorClass.CreateRecord(); returnrec.payload = a.payload + b.payload; result = returnrec; return result; }
Problematic are the operator IntDivide and LogicalXor because they don't have counterparts in C#. Delphi2C# converts IntDivide to a normal Divide operator /. As long as there isn't an additional Divide operator this will work. There is no automatic for LogicalXor yet.
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |